django-behave

I like BDD. I like cucumber.

I like python. I like django.

I don’t like lettuce, a commonly-used python port of cucumber, when used with django. They’ve chosen the completely daft option to use your main database when testing. I’d forgotten this, so when I discovered I’d torched my production database just because I wanted to write a test, I decided to not touch lettuce again…

And then I discovered behave, which works fine as a python BDD tool; except it doesn’t have an easy tie-up with django.

http://packages.python.org/behave/

So I wrote one.

https://github.com/rwillmer/django-behave

It’s a Work-in-Progress, but I’m using it for my developments, so its definitely usable. Comments, etc, very welcome – please use github for this.

Rachel

Django GeoIP templatetag

I’ve published 2 template tags for use with GeoIP at geoip.py.

Hope they may be of use…

Usage:

# Templatetag get_country_name returns the client’s country code
#
# Example:
# {% ifequal get_country “GB” %}
# do something
# {% endifequal %}

# Templatetag get_country sets the given variable name
# to the client’s country code
#
# Example:
# {% get_country as my_country %}
# {% ifequal my_country “GB” %}
# do something
# {% endifequal %}

Django App Quick Start

I wanted to start writing a Django app which was to allow a user to enter data in various tables, and then run a workflow process.

I liked the admin front-end but thought I needed to do something clever with generic views to replicate this in my own application.

So I asked this question on the django-users list

On 04/09/05, Rachel Willmer  wrote:
> I want to use the generic view mechanism to add/change/delete but I
> don't want to have to write my own form template for each page.
> 
> I'd like it to work just like the admin interface does. Is it
> possible/sensible to hook into the admin code which seems to use
> add_stage/change_stage to automatically generate the templates? Or is
> there a better way of doing this?
> 
> Any pointers welcome...
> Rachel

Now I’ve read a bit more about it, the answer is of course to just use the admin interface. 🙂

django-admin.py includes a useful command “adminindex”, which will auto-generate a copy of the admin interface index page.

So generate that, and copy it into your template directory to over-ride the inbuilt one, as described in Tutorial2

Then you can modify that as you wish…

Hey presto, instant application front end that you can use as the basis for the new application…

In retrospect, this is obvious and documented in the Django tutorial. But at the time, I was thinking in terms of “admin” interface and “main” interface, and it slipped past me that I could in fact use the admin interface *as* the main interface…

That might not work too well for most web applications, but for my purposes, (a local single-user application), it will work just fine…

Rachel

Django for Python websites

I’ve just taken a look at Django for the first time, and am seriously impressed.

For a while now, I’ve been trying to find a way of using Python in websites, and haven’t found anything that works well enough – Zope, Cheetah, mod_python – all seem very difficult to get the simplest thing working…

But Django looks like the answer.

The guys behind Django have produced a very useful tutorial to help you get going with it, and the users mailing list seems very responsive…

Very impressed so far…