django

alphabetic filter with generic views

The other day I decided to add a small alphabetic filter to search among the broken packages in debian weather. Searching the net for a nice solution I've found few snippets, but none of them struck me as particularly flexible for my needs.

connect django and rfoo

This evening I spent 30 minutes to try out rconsole in the package rfoo . It's a simple environment to inspect and modify the namespace of a running script.

If you are on debian, you need to install two packages :

sudo aptitude install cython python-dev

Then download the source code. If you want to try it out without installing you have to compile it with the --inplace option :

python setup.py build_ext --inplace

Now you're ready to go.

modify a django model without loosing your data

If you want to modify your model, the diango doc suggests change the model and then manually run ALTER TABLE statements in your db to propagate the changes. This is a bit annoying to do if you have more then X modifications to do. The good reason to avoid automation here, is that if something goes wrong, you loose your data (and backups ??), and nobody, not even a robot overlord, wants to assume this responsability.

upload a file using httplib

I want to share a small snippet of code to upload a file to a remote server as a "multipart/form-data" . The function below gets two arguments. The server url ( ex: http://server.org/upload ) and a filename. First the filename encoded as a "form-data", then we use httplib to POST it to the server. Since httplib wants the host + path in separate stages, we have to parse the url using urlparse.

The receiving server must accept the data and return the location of the newly created resource. There are many snippet on the web, but I felt they were all incomplete or too messy.

add sqlite3 collation with python 2.5 and django

a while ago I wrote about enabling the sqlite3 extension with storm . This is how you do it with the Django ORM. The collation is the same and all details are in the old post. The only tricky part is to establish the connection with cursor = connection.cursor() before calling the function to enable the extension.

dynamic forms with django

Today I started learning how to write web forms in django. My quest was to write a simple search form where I could specify multiple criteria . Django is a very nice and flexible framework written in python and it is also reasonably well documented.

I don't feel writing much today. this is the code :

The tricky part was to understand how to re-display the view and to add a new field. This is easily accomplished in django using the formset class that allows to put display together more then one form. In this case the logic is simple.

Syndicate content