Commits

Kai Diefenbach  committed f99f3ca

Moved WorkflowBase out of models to reduce import dependencies

  • Participants
  • Parent commits e175827

Comments (0)

Files changed (3)

File workflows/__init__.py

-#
+# workflows imports
+import workflows.utils
+
+class WorkflowBase(object):
+    """Mixin class to make objects workflow aware.
+    """
+    def get_workflow(self):
+        """Returns the current workflow of the object.
+        """
+        return workflows.utils.get_workflow(self)
+
+    def remove_workflow(self):
+        """Removes the workflow from the object. After this function has been
+        called the object has no *own* workflow anymore (it might have one via
+        its content type).
+
+        """
+        return workflows.utils.remove_workflow_from_object(self)
+
+    def set_workflow(self, workflow):
+        """Sets the passed workflow to the object. This will set the local
+        workflow for the object.
+
+        If the object has already the given workflow nothing happens.
+        Otherwise the object gets the passed workflow and the state is set to
+        the workflow's initial state.
+
+        **Parameters:**
+
+        workflow
+            The workflow which should be set to the object. Can be a Workflow
+            instance or a string with the workflow name.
+        obj
+            The object which gets the passed workflow.
+        """
+        return workflows.utils.set_workflow_for_object(workflow)
+
+    def get_state(self):
+        """Returns the current workflow state of the object.
+        """
+        return workflows.utils.get_state(self)
+
+    def set_state(self, state):
+        """Sets the workflow state of the object.
+        """
+        return workflows.utils.set_state(self, state)
+
+    def set_initial_state(self):
+        """Sets the initial state of the current workflow to the object.
+        """
+        return self.set_state(self.get_workflow().initial_state)
+
+    def get_allowed_transitions(self, user):
+        """Returns allowed transitions for the current state.
+        """
+        return workflows.utils.get_allowed_transitions(self, user)
+
+    def do_transition(self, transition, user):
+        """Processes the passed transition (if allowed).
+        """
+        return workflows.utils.do_transition(self, transition, user)

File workflows/models.py

 from permissions.models import Permission
 from permissions.models import Role
 
-# workflows imports
-import workflows.utils
-
-class WorkflowBase(object):
-    """Mixin class to make objects workflow aware.
-    """
-    def get_workflow(self):
-        """Returns the current workflow of the object.
-        """
-        return workflows.utils.get_workflow(self)
-
-    def remove_workflow(self):
-        """Removes the workflow from the object. After this function has been
-        called the object has no *own* workflow anymore (it might have one via
-        its content type).
-
-        """
-        return workflows.utils.remove_workflow_from_object(self)
-
-    def set_workflow(self, workflow):
-        """Sets the passed workflow to the object. This will set the local
-        workflow for the object.
-
-        If the object has already the given workflow nothing happens.
-        Otherwise the object gets the passed workflow and the state is set to
-        the workflow's initial state.
-
-        **Parameters:**
-
-        workflow
-            The workflow which should be set to the object. Can be a Workflow
-            instance or a string with the workflow name.
-        obj
-            The object which gets the passed workflow.
-        """
-        return workflows.utils.set_workflow_for_object(workflow)
-
-    def get_state(self):
-        """Returns the current workflow state of the object.
-        """
-        return workflows.utils.get_state(self)
-
-    def set_state(self, state):
-        """Sets the workflow state of the object.
-        """
-        return workflows.utils.set_state(self, state)
-
-    def set_initial_state(self):
-        """Sets the initial state of the current workflow to the object.
-        """
-        return self.set_state(self.get_workflow().initial_state)
-
-    def get_allowed_transitions(self, user):
-        """Returns allowed transitions for the current state.
-        """
-        return workflows.utils.get_allowed_transitions(self, user)
-
-    def do_transition(self, transition, user):
-        """Processes the passed transition (if allowed).
-        """
-        return workflows.utils.do_transition(self, transition, user)
-
 class Workflow(models.Model):
     """A workflow consists of a sequence of connected (through transitions)
     states. It can be assigned to a model and / or model instances. If a
         """Returns all objects which have this workflow assigned. Globally
         (via the object's content type) or locally (via the object itself).
         """
+        import workflows.utils
         objs = []
 
         # Get all objects whose content type has this workflow
         obj
             The object which gets the workflow.
         """
+        import workflows.utils
+
         ctype = ContentType.objects.get_for_model(obj)
         try:
             wor = WorkflowObjectRelation.objects.get(content_type=ctype, content_id=obj.id)
 
 class WorkflowObjectRelation(models.Model):
     """Stores an workflow of an object.
-    
-    Provides a way to give any object a workflow without changing the object's 
+
+    Provides a way to give any object a workflow without changing the object's
     model.
 
     **Attributes:**

File workflows/tests.py

     self.private.transitions.add(self.make_public)
     self.public.transitions.add(self.make_private)
 
-    self.w.get_initial_state() = self.private
+    self.w.get_initial_state = self.private
     self.w.save()
 
 # Taken from "http://www.djangosnippets.org/snippets/963/"