Commits

offline  committed 3b8a97d

signals decorator added

  • Participants
  • Parent commits 2ce1755

Comments (0)

Files changed (1)

File annoying/decorators.py

      - template: template name to use
 
     Examples:
-    # 1
+    # 1. Template name in decorator parameters
 
     @render_to('template.html')
     def foo(request):
                                   {'bar': bar}, 
                                   context_instance=RequestContext(request))
 
-    # 2
+
+    # 2. Template name as item value in return dictionary
 
     @render_to()
     def foo(request, category):
             return render_to_response(tmpl, output, context_instance=RequestContext(request))
         return wrapper
     return renderer
+
+
+
+def signals(signal, sender, **kwargs):
+    """
+    Django signals as decorators
+
+    Usage example:
+        @signals(post_save, sender=Vote)
+        def vote_added(sender, **kwargs):
+            ...
+    """
+    def wrapper(function):
+        signal.connect(function, sender) 
+        return function
+    return wrapper