summaryrefslogtreecommitdiff
path: root/django/dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'django/dispatch')
-rw-r--r--django/dispatch/__init__.py2
-rw-r--r--django/dispatch/dispatcher.py16
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