Hi Django developers,
Usually, signal receivers are defined as functions and then connected
to a specific signal via a function call outside of the defined
function. This can cause clutter, it violates DRY, and it is not very
Pythonic in style. Several examples of the current usage pattern are
included in the Django documentation, and I don't need to go into too
much detail because the majority of people on this list know what I'm
talking about.

I propose a decorator method, to be added to the Signal class, which
would allow you to decorate a signal receiver function and therefore
skip the explicit call to signal_instance.connect(...). The usage of
such a method would look something like this:

<code>
from django.db.models.signals import pre_save

@pre_save.deco_connect(sender=MyModel) # Could use another name for
the method...
def receiver(sender, instance, *args, **kwargs):
    pass # Do something here.
</code>

I've already written a method like this, and it's very simple in
implementation. It also allows you to specify optional keyword
arguments, but works without them also. Please consider this for
inclusion into the Django trunk.

Regards,
Zack
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to