Monday, April 9, 2012

Django signals

Simplificated version of Django signal.connect function, but it insert the receiver as the first receiver of the list. The default behavior is to add it in the final. To this algorithm makes sense, it must be called just once per signal, so use it in very special cases. Código:

def connect_as_first_signal(signal, receiver, sender=None, dispatch_uid=None): "Similar to signal.connect(receiver, sender=sender), but put the receiver as the first element in the list." from django.dispatch.dispatcher import _make_id if dispatch_uid: lookup_key = (dispatch_uid, _make_id(sender)) else: lookup_key = (_make_id(receiver), _make_id(sender)) signal.lock.acquire() try: for r_key, _ in signal.receivers: if r_key == lookup_key: break else: signal.receivers.insert(0, (lookup_key, receiver)) finally: signal.lock.release() Usage: from django.db.models.signals import pre_save connect_as_first_signal(pre_save, SUA_FUNCAO_DE_CALL_BACK, sender=SEU_SENDER, dispatch_uid=SEU_ID)

Saturday, April 7, 2012

Django Dynamic Fixture in GitHub


Finally!

http://paulocheque.github.com/django-dynamic-fixture

https://github.com/paulocheque/django-dynamic-fixture

https://github.com/paulocheque/django-dynamic-fixture/wiki

Latest version: 1.6.1

Saturday, October 29, 2011

Django: Amount of queries in each test


Django-Dynamic-Fixture 1.4.0 has bugfixes and new features:

- Report with the amount of queries executed in each test method: manage.py test --with-queries
- Count how many queries are executed in the insert and update of a model instance (this can change according to listeners, override of the method save etc): manage.py count_queries_on_save

http://code.google.com/p/django-dynamic-fixture/

Sunday, October 9, 2011

Feature Flip for Continuous Deployment? Django Intruder


Most popular tools to activate and dsactivate features in Django are intrusive, in other words, it is necessary to include an additional code to make possible a feature to be disabled or enabled. This approach is interesting, but complex to solve a simple problem, besides that it is not a 100% dynamic solution.

Django Intruder is a simple solution and unobtrusive to the application. Without any extra code it is possible to disable any request to the Web site.

http://code.google.com/p/django-intruder/

http://pypi.python.org/pypi/django-intruder