← July August November →

newcomments are in trunk

Just a short message concerning the Google Summer of Code.

I’m proud to report that the Google Summer of Code student Thejaswi Puthraya that I had the privilege to mentor this year, not only finished his task successfully but also did that in time for Django 1.0!

Changeset 8557 has all the interesting details, so hop over to the new and shiny comments documentation and enjoy. Huge thanks to Jacob for his groundwork and the documentation work.

Django Aug. 26, 2008, 10:58 a.m. comments (4)

Easy overrides for absolute URLs of reusable apps

Welcome to the new jannisleidel.com, after finally being migrated from Wordpress to Django. I’m now a happy user of James Bennett’s Coltrane app. It provides the features I used in the old Wordpress installation and is simple enough to be hacked in the spare time. One thing though was new to me and I want to share this little piece of usefulness with you.

By default Coltrane uses a URL scheme for the weblog entries like:

r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$'

If you want to change that URL scheme without modifying Coltrane you can fairly easily override the provided URLconf with your own. For example I’m using the following regular expression here:

r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[-\w]+)/$'

But this is only half the battle. Furtunately, Coltrane uses absolute URLs for the entry models. And this is when a special setting needs to be brought into play: ABSOLUTE_URL_OVERRIDES — “A dictionary mapping “app_label.model_name” strings to functions that take a model object and return its URL.”

Combined with the reverse() utility it’s a nice, small solution, you can put in the settings.py file of your site:

from django.core.urlresolvers import reverse
ABSOLUTE_URL_OVERRIDES = {
    'coltrane.entry': lambda o: reverse('coltrane_entry_detail', kwargs={
                                            'year': o.pub_date.strftime('%Y'),
                                            'month': o.pub_date.strftime('%m'),
                                            'slug': o.slug }),
}

Django Aug. 21, 2008, 4:03 p.m. comments (3)