diff options
author | Arthur Koziel <arthur@arthurkoziel.com> | 2010-09-13 00:04:27 +0000 |
---|---|---|
committer | Arthur Koziel <arthur@arthurkoziel.com> | 2010-09-13 00:04:27 +0000 |
commit | dd49269c7db008b2567f50cb03c4d3d9b321daa1 (patch) | |
tree | 326dd25bb045ac016cda7966b43cbdfe1f67d699 /django/dispatch | |
parent | c9b188c4ec939abbe48dae5a371276742e64b6b8 (diff) | |
download | django-soc2010/app-loading.tar.gz |
[soc2010/app-loading] merged trunkarchive/soc2010/app-loadingsoc2010/app-loading
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13818 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/dispatch')
-rw-r--r-- | django/dispatch/__init__.py | 2 | ||||
-rw-r--r-- | django/dispatch/dispatcher.py | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/django/dispatch/__init__.py b/django/dispatch/__init__.py index 0798acc7db..9aeb83c5e1 100644 --- a/django/dispatch/__init__.py +++ b/django/dispatch/__init__.py @@ -6,4 +6,4 @@ See license.txt for original license. Heavily modified for Django's purposes. """ -from django.dispatch.dispatcher import Signal
\ No newline at end of file +from django.dispatch.dispatcher import Signal, receiver
\ No newline at end of file diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py index de09334637..c4516d88b0 100644 --- a/django/dispatch/dispatcher.py +++ b/django/dispatch/dispatcher.py @@ -235,3 +235,19 @@ class Signal(object): for idx, (r_key, _) in enumerate(self.receivers): if r_key == key: del self.receivers[idx] + + +def receiver(signal, **kwargs): + """ + A decorator for connecting receivers to signals. Used by passing in the + signal and keyword arguments to connect:: + + @receiver(post_save, sender=MyModel) + def signal_receiver(sender, **kwargs): + ... + + """ + def _decorator(func): + signal.connect(func, **kwargs) + return func + return _decorator |