Skip to main content


Showing posts from February, 2006

Python: Django Custom Tags

In my last post, I complained that code like the following is redundant:<tr class="fieldrow">
<th><label for="id_subject">Subject:</label></th>
{{ form.subject }}<br>
{% if form.subject.errors %}
<div class="error">{{ form.subject.errors|join:", " }}</div>
{% endif %}

<tr class="fieldrow">
<th><label for="id_name">
Poster's Name:
{{ }}<br>
{% if %}
<div class="error">{{|join:", " }}</div>
{% endif %}

<tr class="fieldrow">
<th><label for="id_email">
Poster's Email:
{{ }}<br>
{% if %}
<div class="error">{{ …

Python: Django-palooza

I think the Django guys have written some really nice software. It's good stuff. No, it won't cure cancer; it's not a CMS; it's not a shopping cart; but it does what it does well.

In fact, I must admit that I felt really at home using Django. Django + WSGI reminds me a lot of how Aquarium works. In many subtle places, the designs are very similar. There are some things I feel Aquarium does better, but I can readily admit there are some things that Django does better. Despite the fact that I too am a perfectionist, I think Django may be more polished--apparently, one perfectionist just can't code as fast as two perfectionists ;) Actually, I wish it was closer to meeting my needs (stackless Python, coroutines, a custom data store instead of an RDBMS, etc.), but I can appreciate it for what it is.

Since Django can't possibly meet everyone's needs--for instance, it doesn't make a good replacement for Linux or Vim (yes, that's a joke)--let me state some of…

Linux: Ubuntu 5.10 on Dell Inspiron B130

If you read my last post, you may be relieved to hear that I did not set my laptop on fire. Ubuntu is working great! It even supported suspend to disk out of the box! I haven't been able to do this in a good five years. The only mildly tricky thing was that I needed to follow the instructions on this forum in order to get it to support WXGA resolutions (i.e. 1280x800). I'll probably need to use NDIS to get the wireless card to work, but I haven't gotten to that yet.

I guess I should go write a Linux on Laptops page now.

Linux: Fedora Core 4 on Dell Inspiron B130

Rant warning:

If you're thinking about buying a Dell Inspiron B130 for use with Fedora Core 4, my initial assessment is don't:If you use the automatic partitioning, you'll get an exception during install. This may be Fedora's fault, though, because I've seen this problem before.
After the installation actually started installing RPMSs, it just froze and died. It may have been display related, but I'm not sure.
I installed in text mode (HTTP install) with the bare minimal number of packages. But then, when it tried to boot, it froze on the line, "Initializing hardware... storage network".
I know that the display is hard to get working, but I've heard it just comes down to getting the right mode line, "Modeline "1280x800" 80.58 1280 1344 1480 1680 800 801 804 827".Well, I will continue the battle tomorrow. It's too late for me to return this laptop. I'm not a happy camper at this moment. Apparently, very few people have…

Python: Recursion in Django Templates

Whenever learning a new Web technology, I like to write a bulletin board application. It's easy, I have it memorized, and it gives me a chance to compare and contrast the new technology with what I already know. See here for the application written in Aquarium.

The thing that was hardest about using Django templates to write this application was the lack of functions and recursion in the templating engine. Recursion is really suitable for generating a hierarchy of messages. This post is about how I had to work around the problem. I got it to work, but it wasn't what I'd call elegant.

To use Django to generate a page that looks like this, you break it up into a few steps. First, you create a template that has everything other than the hierarchy of messages. I called it "index.html":{% comment %}
Output the messages, and output a message input form.
{% endcomment %}

{% extends "bulletinboard/vertical" %}

{% block vertical_body %}
<div class="c…

Python: Django Templates

"As simple as possible, but no simpler."

I have a lot of respect for what the Django guys have done. I actually really like a lot of Django. However, having tried it, I find the templating engine to be elegant, but too simple. What frustrates me most is the lack of functions. In my first programming class, I learned how to use functions for code reuse. DRY applies even to HTML. At my company, even the "template authors" know how to create a function to avoid code duplication. Nor is the "include" or "block" statement a suitable replacement--functions have parameters. Different arguments lead to different results. This is necessary functionality. Also, functions should support recursion. I learned in my second programming class how to think recursively, and every once in a while it really comes in handy (for instance, when you're writing a bulletin board application with a hierarchy of messages).

When I was using Django templates, I …

Python: Clearing sys.modules of Stale Modules

I'm posting this here in case someone might find it useful. I also submitted it to the Cookbook.
"""Clear ``sys.modules`` of specific types of modules if one is stale.

BASIC IDEA: Clear ``sys.modules`` of stale code without having to restart your
server. It's a hell of a lot harder to do right then it sounds.


__docformat__ = "restructuredtext"

_lastModuleUpdate = time.time()
def clearModules():
"""Clear ``sys.modules`` of specific types of modules if one is stale.

See ``properties.CLEAR_MODULES``.

I took this method out of the ``InternalLibrary`` class so that you can
call it *really* early, even before you create a ``Context`` to pass to


The problem that this method solves is simple: if I change a file, I don't
want to have to restart the server. It's a simple problem, but it's tough
to implement right. To prevent repeating mistakes, here'…

Microsoft: A [Very] Small Victory

I recently bought three laptops from Dell. They came with Windows XP Home edition. I'm a passionate Linux guy. Microsoft and Dell have a deal where Dell can only sell computers (perhaps it's just their consumer stuff?) with Windows on them. Furthermore, as part of this deal, Dell cannot reveal how much each copy costs. Dell refused to sell me the laptops with no software. After getting the laptops, I called up customer support to try to arrange a refund on Microsoft licenses I didn't want. I had to insist on talking with a supervisor. He called me back hours later. I pleaded my case. He argued strongly that the software didn't cost me anything, it was part of the package. I argued strongly that somehow Microsoft was getting my money, and I wanted no part in that. I wanted $100 back per laptop. He argued that since the cost of my laptops was so low (they were the cheapest models), he didn't feel that Dell could possibly be spending $50 a piece. After s…