Search

Thursday
Sep222011

Installing mod_python on Freebsd 8.2

The other day I was setting up a fresh freebsd jail to act as host for a django based web site. I restarted apache and was given this error: 

Syntax error on line 46 of /usr/local/etc/apache22/extra/httpd-vhosts.conf:
Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the ser
ver configuration

Luckily I knew my mistake, I'd forgotten to install mod_python. I went to install it from ports and it failed to build...

demo# cd /usr/ports/www/mod_python
demo# make
===>  ap22-mod_python-2.7.11 : Error from bsd.apache.mk. apache22 is installed (or APACHE_PORT is
defined) and port requires apache13 at most.

Slightly stumped, I searched around for a solution but couldn't find one. I eventually worked out that you need the mod_python3 package with apache22...

demo# whereis mod_python3
mod_python3: /usr/ports/www/mod_python3
demo# cd /usr/ports/www/mod_python3
demo# make

Hopefully this will help someone and remind me in future.

Finally if you're wondering why we're still using mod_python don't worry we're planning on switching to mod_wsgi within the next couple of months.

Sunday
Sep182011

Problems installing Fabric on OSX lion 

I tried to install fabric on OSX lion today and it failed on pycrypto with this error:

error: Setup script exited with error: command 'llvm-gcc-4.2' failed with exit status 1

To fix install xcode 4 from the mac store. Unfortunately it is a big download (3.17GB) and takes an age to install.

Reference:

 

Sunday
Sep042011

Bootstrap and Django

Last Friday I started to play with bootstrap, a toolkit designed to kickstart web apps and site development. After spending many hours over the holiday weekend mocking up a new app I was hooked.

I thought I'd create a django base setup using the bootstrap CSS along with my favourite/essential django apps. Items included in the base:

  • Bootstrap CSS theming (forms, nav bar and basic alerts)
  • Working ajax example with cross site request forgery protection (csrf)
  • Working login and logout example using django-registration
  • Django extensions - shell_plus etc
  • Django evolution for future database changes
  • jQuery

To use the base:

  1. Clone or fork djangobase from github
  2. Install the packages listed in README
  3. Create the database (python manage.py syncdb)
  4. Fire up the test server (python manage.py runserver ...)

Next week I'll add a modal dialog and an autocomplete widget.

References:

Screenshot:

Monday
Aug292011

Useful things I've learnt this week (HTML5, CSS3 and Egypt)

HTML5 Boilerplate

I have heard lots of good things about HTML5 boilerplate so I took the plunge this week and was very impressed. It's so easy to get a site up and running with an emphasis on cross browser use. Areas that impressed me most were the inclusion of clearfix and Modernizr which is truly magical!

I'll post the site URL soon as I'm still working through some javascript issues on IE6 and IE7 so it's not quite ready for public consumption yet. 

CSS3 Pie

I'm a believer in graceful browser degradation and people using the latest browsers being rewarded with features like border-radius, box-shadow. Unfortunately a site I was working on had to have rounded corners on IE 7 and 8. I wanted the site to be responsive so didn't want to go down the image route. CSS3 Pie came to the rescue...

  1. Download CSS3 pie
  2. Put pie.js and pie.htc in the relevant folder to be served up.
  3. Create a CSS rule with border-radius and add the relevant CSS3 pie code snippet to the end of the rule:
.main { 
   border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; 
   behavior: url(/static/js/PIE.htc);
}    

I'm aware this isn't the only javascript tool that provides CSS3 features on older web browsers but this is the only one I know about where you can select the individual elements, e.g. it's not all or nothing.

The Rosetta Stone

I visited the British museum this week for the first time and came across the Rosetta stone. I never it knew it was in the UK. Very impressive piece of history. A lot bigger than I imagined and that was in the setting of a huge hall with large Egyptian statues. Obviously I'm referring to the ancient Egyptian stone not the foreign language learning tool. I wouldn't be so impressed to see a DVD in a glass cabinet, unless it was the Rambo boxset (the one with the hand grenade).

References

Friday
Aug192011

Useful things I've learnt this week (Django, Python, jQuery UI)

Combining Django Querysets

It is possible to combine django querysets by using "|".

queryset1 = models.Table1.objects.filter(name__icontains="wand")
queryset2 = models.Table2.objects.filter(name__icontains="it")
queryset = queryset1 | queryset2

Note: This shouldn't be used a substitue for lookups using Django Q objects.

lstrip and Python

I needed to strip the leading 0 from some python dates and came across lstrip. Perfect for the job...

day = "01"
day.lstrip("0")
'1'

If there's a better way of doing this please let me know.

Disabling Days in jQuery's datepicker

I needed to disable certain days in a jquery query ui datepicker calendar.

For the code below you'll need an array of dates called bookedDays. Each date must be in the format YEAR-M-D, e.g. 2011-1-1 or 2011-8-12. You must not having the leading zeros on the month or days. If you're using python to get your lists of dates see lstrip above :) .

function disabledDays(date) { 
    var m = date.getMonth(), d = date.getDate(), y = date.getFullYear(); 
    for (i = 0; i < bookedDays.length; i++) { 
        if($.inArray(y + '-' + (m+1) + '-' + d,bookedDays) != -1) { 
            return [false] } 
    } return [true]; 
}

$("#datepicker").datepicker({minDate: 1, 
                             maxDate:'+3m', 
                	     beforeShowDay: disabledDays,
                	     dateFormat: "yy-mm-dd",
                	     onSelect: function(dateText, inst) {
                	     dayselect(dateText);
                		},		
                	});

Unfortunately I can't take credit for all of datepicker code above as it has been adapted from David Walsh's blog.

References: