1. Peter Sanchez
  2. django-callback

Commits

Peter Sanchez  committed 0ef3dec

Moved all imports to absolute. My bad...

  • Participants
  • Parent commits a0e1cf9
  • Branches default

Comments (0)

Files changed (5)

File callback/__init__.py

View file
  • Ignore whitespace
-from callback import callback_manager
-from base import CallbackException, CallbackBase
-from signals import stored_callback, processed_callback, error_callback
+from callback.callback_manager import callback_manager
+from callback.base import CallbackException, CallbackBase
+from callback.signals import stored_callback, processed_callback, error_callback
 
 
-__version__ = '0.4'
+__version__ = '0.5'
 __all__ = [
     'CallbackException', 'CallbackBase', 'callback_manager',
     'stored_callback', 'processed_callback', 'error_callback',

File callback/callback.py

  • Ignore whitespace
-from django.db import models
-from models import CallbackMap
-from base import CallbackException, CallbackBase
-from signals import stored_callback, processed_callback, error_callback
-
-REQUIRED_METHODS = ('process',)
-
-
-class CallbackManager(object):
-    def __init__(self):
-        self._callbacks = {}
-
-    def validate_methods(self, cls):
-        for method in REQUIRED_METHODS:
-            if not hasattr(cls, method):
-                raise CallbackException(
-                    'Cannot register class - does not contain '
-                    '%s method' % method
-                )
-
-    def register_callback(self, dest_model, dest_cls):
-        if not issubclass(dest_model, models.Model):
-            raise CallbackException(
-                'Cannot register model - not a '
-                'subclass of django.db.models.Model'
-            )
-        if not issubclass(dest_cls, CallbackBase):
-            raise CallbackException(
-                'Cannot register class - not a subclass of '
-                'callback.CallbackBase'
-            )
-
-        self.validate_methods(dest_cls)
-        self._callbacks[dest_model] = dest_cls
-
-    def unregister_callback(self, dest_model):
-        self._callbacks.pop(dest_model, None)
-
-    def get_callback_class(self, dest_model):
-        for model, cls in self._callbacks.items():
-            if isinstance(dest_model, model):
-                return cls()
-        raise CallbackException('Model class is not registered.')
-
-    def store_callback(self, model_instance):
-        if not model_instance.pk:
-            model_instance.save()
-
-        cls = self.get_callback_class(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
-        cls = self.get_callback_class(model)
-        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))
-            error_callback.send(
-                sender=self,
-                callback_instance=callback_instance,
-                model_instance=model,
-            )
-            raise CallbackException(str(e))
-
-
-callback_manager = CallbackManager()

File callback/callback_manager.py

View file
  • Ignore whitespace
+from django.db import models
+from models import CallbackMap
+from base import CallbackException, CallbackBase
+from signals import stored_callback, processed_callback, error_callback
+
+REQUIRED_METHODS = ('process',)
+
+
+class CallbackManager(object):
+    def __init__(self):
+        self._callbacks = {}
+
+    def validate_methods(self, cls):
+        for method in REQUIRED_METHODS:
+            if not hasattr(cls, method):
+                raise CallbackException(
+                    'Cannot register class - does not contain '
+                    '%s method' % method
+                )
+
+    def register_callback(self, dest_model, dest_cls):
+        if not issubclass(dest_model, models.Model):
+            raise CallbackException(
+                'Cannot register model - not a '
+                'subclass of django.db.models.Model'
+            )
+        if not issubclass(dest_cls, CallbackBase):
+            raise CallbackException(
+                'Cannot register class - not a subclass of '
+                'callback.CallbackBase'
+            )
+
+        self.validate_methods(dest_cls)
+        self._callbacks[dest_model] = dest_cls
+
+    def unregister_callback(self, dest_model):
+        self._callbacks.pop(dest_model, None)
+
+    def get_callback_class(self, dest_model):
+        for model, cls in self._callbacks.items():
+            if isinstance(dest_model, model):
+                return cls()
+        raise CallbackException('Model class is not registered.')
+
+    def store_callback(self, model_instance):
+        if not model_instance.pk:
+            model_instance.save()
+
+        cls = self.get_callback_class(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
+        cls = self.get_callback_class(model)
+        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))
+            error_callback.send(
+                sender=self,
+                callback_instance=callback_instance,
+                model_instance=model,
+            )
+            raise CallbackException(str(e))
+
+
+callback_manager = CallbackManager()

File callback/models.py

View file
  • Ignore whitespace
 from django.db import models
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.contenttypes import generic
-from managers import CallbackMapManager
+from callback.managers import CallbackMapManager
 
 
 class CallbackMap(models.Model):

File setup.py

View file
  • Ignore whitespace
 
 setup(
     name='django-callback',
-    version='0.4',
+    version='0.5',
     package_dir={project_name: project_name},
     packages=packages,
     package_data={project_name: data_files},