2009-01-17

Snakes in the bassinet (Baby's first open source project)

I pushed out my first open source project this week. It's a Python interface to HelpSpot's web services API. HelpSpot is a help desk application that I use, like and happily recommend.

You can find my project python-helpspot on GitHub. I have another open source thing in the works too. That one is going to be a doggy and it'll have a touch of the django.

2009-01-08

Missteps in Django - Part 3

This one will make it obvious that the missteps are my own mistakes, not problems inherit in Django. I'm not terribly embarrassed to look this dumb. Most days, I'm proud of my density. On with the show!

I guess this is another template issue. Oh well. I wanted to set the CSS class on an HTML tag based on some dynamic data. In this case, the data was the status field on my Shipment model:


class Shipment(models.Model):
description = models.TextField()
created = models.DateTimeField(auto_now_add=True);
status = models.CharField(max_length=64, default="new",
choices=STATUS_CHOICES)

I'm omitting STATUS_CHOICES because its not important to my point. I wanted each displayed shipment to have a different background color. My initial idea was to try something like this:

class={% ifequal thing.status "new" %}"new"{% elifequal thing.status "exception" %}"exception"{% endelifequal %}...

Of course, Django doesn't have an elif construct in its templates. Doesn't matter because my idea was stupid and eventually I figured that I could do this:

class="status_{{ shipment.status }}"

and be done with it. I hope I had a good laugh at myself.