Brad's Blog

web dev, django, running, food, or whatever

mod_python checks your blood pressure 2009-03-24

I'm deploying a django project using mod_python... now, usually I will just use my package management tools to install a binary version, but this time I need to build it from source.As I get ready to go through the whole configure/make/make install process, I peruse the output of configure just to make sure everything is ok...checking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether ...

Scheduled Tasks (or cron jobs) with Django 2009-02-20

This is my take on setting up cron jobs for the apps in a Django project. It is based on my own convention, and it solves my initial problems where I want to perform some action on all of my Django apps at a periodic interval (currently this is a once-a-day task).In order for this to work, I create a cron.py module for all of my INSTALLED_APPS. This module must contain a run method. Other than that, it ...

A Custom form for Django's Automatic Admin. 2009-01-14

A huge selling-point for Django (at least for developers) is its Automatic Admin. However, the ease at which the Admin can be set up, might make one second-guess an attempt to customize what is provided by default. Of course, the default admin site may not be without its drawbacks...Many of the django Apps that I have built, tap into Django's User Authentication System. Simply put, when I build a model, it has a Foreign Key to django's ...

Add a Context Processor for your Django app using Sites 2009-01-05

I've recently refactored a significant number of my Django Apps so that they include the "sites" framework. Essentially, this allows me to use the same code (and database) for multiple sites. For Example, if I was was building a CMS (and I am!), I might have a model that defines a "page":from django.db import modelsfrom django.contrib.auth.models import Userfrom django.contrib.sites.models import Siteclass Page(models.Model): title = models.CharField('title', max_length=255) content ...

Morphology is Fun! 2009-01-04

Morphological operations are very common in image processing. The two most basic of these are Erosion and Dilations, and from these, additional morphological operations can be performed. While there is an abundance of literature on the topic of morphology, I often like to view concrete examples of the operations. So, I've published a few images that illustrate the output of 1-to-5 iterations of various morphological operations --erosion, dilation, opening, closing, gradient, top hat, and black hat--with various structuring elements--rectangle ...

How to convert HTML to PDF using Python. 2008-12-17

I'm building web-based, data-driven apps using Django. Eventually (or unfortunately), I will need to generate some reports that are printer-friendly. Logically, PDF is the format for such files... so how am I going to convert my xHTML and CSS to a nice-looking PDF document?The Django Book has a whole chapter dedicated to Generating Non-HTML Content. They seem to to be fond of ReportLab ToolKit. The caveat here, though, is that you need to know a bit about the ...

radiohead - 15 steps video 2008-12-04

Updated... BIZRADv2... is a bit better.rh.createWidget("BIZRADV2", "4G5D1F9F2F0G8I9H1F5F2E0D5E1F7C8F5GaK3E1G5D1C2E4C8C9C7C6F4D5DaD9E8D5D1K9D8D7D1D0G5D2E1D4DaD9D6D3E5D1C2E5D3D4DbD0D4E1D5DaD9D8C7H2D4E9E7D5C1E3D1D2D5D7C8EaD9D1H3D1D7DaE6D5C1D3E7F4D8CaD9DaD1C2C1C0F2C1C2D0D7D8D6E9FaH3C4F1G3H5F4E0E1G8DaC9D3E2G1D5E8C7E6E4C3E0CaFbD7J");

That Looks about Right 2008-12-04

history | awk '{ print $2 }' | sort | uniq -c | sort -rn | head 152 cd 145 ll 73 vi 20 rm 18 svn 13 exit 9 ls 8 grep 7 php 5 wgetvia b-list.org

A simple Django example with Ajax 2008-11-24

I often employ Ajax in HTML forms in order to update the list of options in select elements. For example, suppose a form consists of two select elements, and the options in the second depends on the values selected in the first. A simple example of this might be an Automobile Rental website that lets you choose the type of vehicle as well as the color. Not all vehicles come in the same color, though, so you might have a ...

Extending Django's MultiWidget: SplitSelectDateTimeWidget 2008-11-19

This entry is an update to SelectTimeWidget: A custom Django Widget. The Problem: I want to use a Single widget object for a DateTimeField, but I want it to consist of select elements with appropriate options for month, day, year, hour, minute, and second. Additionally, I want to be able to specify a 12-hour format, so I would then need options for "a.m." and "p.m."Fortunately, Django's SelectDateWidget (from django.forms.extras.widgets) takes care of the ...