Blog Archive for November 12, 2010

Unicode Regular Expressions in Python

November 12, 2010

I was struggling with some unicode issues in Python. I wanted my app to match Eikanger-Bjørsvik Musikklag, which contained extended characters.

I was able to achieve this by doing the following:

Regex

Prefixing my regular expression with ur made it into a unicode raw string:

lRegEx = ur'\s*([\w\(\)&\' …

Apache Environment Variables and mod_wsgi

November 12, 2010

I need to be able to pass Apache Environment Variables, set on a per VirtualHost basis, through to a Django application. These need to be variables set in Apache via SetEnv, rather than operating system environment variables, as they will change for each VirtualHost.

VirtualHost config

In the Apache virtual …

jQuery Mobile, Django and Collapsible

November 12, 2010

This article follows on from two previous ones, available at http://drumcoder.co.uk/blog/2010/nov/12/jquery-mobile-basics/ and http://drumcoder.co.uk/blog/2010/nov/12/jquery-mobile-and-django/. Please read both those first.

This article covers the results page. This is a Django generated list of contest results for a given band, with collapsible details underneath, working like an Accordion.

Band Links

The links …

jQuery Mobile and Django

November 12, 2010

In our previous article (http://drumcoder.co.uk/blog/2010/nov/12/jquery-mobile-basics/) we built a basic HTML page using jQuery mobile. If you haven't read that, then read that first, because we're going to build on it with some more functionality.

Links

One the homepage we built previously, we had straightforward links to /bands/, using: …

jQuery Mobile Basics

November 12, 2010

Here's some details of how I built a simple site using jQuery Mobile. Future articles look at integrating this with Django, see the links at the end.

First Page

Here's the HTML used on the first page.

<!DOCTYPE html> 
<html> 
    <head> 
    <title>BrassBandResults</title> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" /> …

Django Numerical Positions

November 12, 2010

I wanted to convert the position at a competition into 1st, 2nd, 3rd, 4th etc. Django makes this easy with the humanize template filters.

First of all, you need to add the humanize application to your INSTALLED_APPS:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.humanize', …