New way to catch django signals

During preparations for 1.0 release Django signaling system was refactored. Details on Backwards Incompatible Changes Page, corresponding changeset is 8223.

Well, the main reason of changes is speeding up. Announced “90% improvement in the speed of signal handling“.

The main question is how to update own code to be compatible with new way. We need to replace old style dispatching with new way of signal object creation (django.dispatch.Signal). Let see post and pre save model signal dispatch example.

We have Item model and signal handler add_mime_type declared before. Old style connection:

dispatcher.connect(add_mime_type, signal=models.signals.pre_save, sender=Item)

New way to connect model signals with handlers:

models.signals.pre_save.connect(add_mime_type, sender=Item)

Looks pretty simple. Also we need to change one thing in handler. It must be declared as accepting kwargs. For example:

def add_mime_type(instance, **kwargs):

The main changes are done behind the scenes. Now models.signals.pre_save is instance of django.dispatch.Signal instead of plain object().

Django vs. Pylons

It is a short post-though about two popular Python frameworks. This is my personal experience and some analytics.

Well, if you building long-term project, for example some social network (oh again), usually you need rapid prototyping and then step-by-step (iteration) development. For prototyping you need more and more components, which you can replace or customize later. For iteration-based development you need to setup release deployment and testing automation (aka buildbot). Important thing that you have deployments on own infrastructure and you can build it once and then forget. So Django is number one solution for the component-based model (aka apps).

Other case is when you creating an application which would be highly redistributable, for example blog or e-shop engine. It is really hard (for today) to setup quickly django applications and lots of people is aware of hand-made installations (like terminal commands, etc). Pylons has a better deployment tool (paste) that helps with redistribution of projects and better project/app file layout.

It is main reason why there are still not so much complete django applications.

I thinking to use both for different cases, but anyway large projects is a Django way.

At last my top three django components: 1 Django’s cache framework; 2. User authentication in Django |; 3. Testing Django applications .

Alpha updates

I still lack of time to finish my blog styling and programming, but here some progress:

All this stuff built on Django with few useful apps — Byteflow Blog Engine and django-template-utils. And of course my hand-made python code :-)

For styling I currently use blueprintcss framework. Later I’ll create some custom design and then will code own html/css style.

Today main focus on content!

My code (python/javascript) coming soon too.

code monkey


Tags

Blogroll

Recent bookmarks