e12e119ce5af — Peter Sanchez 13 years ago
Added signals for stored and processed callbacks
2 files changed, 23 insertions(+), 1 deletions(-)

M callback/callback.py
A => callback/signals.py
M callback/callback.py +13 -1
@@ 1,6 1,7 @@ 
 from django.db import models
 from models import CallbackMap
 from base import CallbackException, CallbackBase
+from signals import stored_callback, processed_callback
 
 REQUIRED_METHODS = ('process',)
 

          
@@ 46,7 47,13 @@ class CallbackManager(object):
             model_instance.save()
 
         cls = self.get_callback_class(model_instance)
-        return CallbackMap.objects.store_callback(model_instance)
+        callback_instance = CallbackMap.objects.store_callback(model_instance)
+        stored_callback.send(
+            sender=self,
+            callback_instance=callback_instance,
+            model_instance=model_instance,
+        )
+        return callback_instance
 
     def process_callback(self, callback_instance):
         model = callback_instance.content_object

          
@@ 54,6 61,11 @@ class CallbackManager(object):
         try:
             cls.process(model)
             callback_instance.mark_complete()
+            processed_callback.send(
+                sender=self,
+                callback_instance=callback_instance,
+                model_instance=model,
+            )
         except Exception, e:
             callback_instance.mark_error(str(e))
             raise CallbackException(str(e))

          
A => callback/signals.py +10 -0
@@ 0,0 1,10 @@ 
+from django import dispatch
+
+
+stored_callback = dispatch.Signal(
+    providing_args=['callback_instance', 'model_instance'],
+)
+
+processed_callback = dispatch.Signal(
+    providing_args=['callback_instance', 'model_instance'],
+)