[z3-checkins] r17945 - z3/hurry/trunk/src/hurry/workflow

faassen at codespeak.net faassen at codespeak.net
Wed Sep 28 19:22:38 CEST 2005


Author: faassen
Date: Wed Sep 28 19:22:37 2005
New Revision: 17945

Modified:
   z3/hurry/trunk/src/hurry/workflow/interfaces.py
   z3/hurry/trunk/src/hurry/workflow/workflow.py
   z3/hurry/trunk/src/hurry/workflow/workflow.txt
Log:
Introduce concept of system workflow
transitions. These can be fired from code,
but won't show up in the code that depends
on manual workflow transitions.

Modified: z3/hurry/trunk/src/hurry/workflow/interfaces.py
==============================================================================
--- z3/hurry/trunk/src/hurry/workflow/interfaces.py	(original)
+++ z3/hurry/trunk/src/hurry/workflow/interfaces.py	Wed Sep 28 19:22:37 2005
@@ -3,6 +3,7 @@
 
 MANUAL = 0
 AUTOMATIC = 1
+SYSTEM = 2
 
 class InvalidTransitionError(Exception):
     pass

Modified: z3/hurry/trunk/src/hurry/workflow/workflow.py
==============================================================================
--- z3/hurry/trunk/src/hurry/workflow/workflow.py	(original)
+++ z3/hurry/trunk/src/hurry/workflow/workflow.py	Wed Sep 28 19:22:37 2005
@@ -13,7 +13,7 @@
 from zope.app.event.objectevent import ObjectEvent, ObjectModifiedEvent
 
 from hurry.workflow import interfaces
-from hurry.workflow.interfaces import MANUAL, AUTOMATIC
+from hurry.workflow.interfaces import MANUAL, AUTOMATIC, SYSTEM
 from hurry.workflow.interfaces import\
      IWorkflow, IWorkflowState, IWorkflowInfo, IWorkflowVersions
 from hurry.workflow.interfaces import\
@@ -185,7 +185,7 @@
 
     def fireTransitionToward(self, state, comment=None, side_effect=None,
                              check_security=True):
-        transition_ids = self.getManualTransitionIdsToward(state)
+        transition_ids = self.getFireableTransitionIdsToward(state)
         if not transition_ids:
             raise interfaces.NoTransitionAvailableError
         if len(transition_ids) != 1:
@@ -229,15 +229,24 @@
                 transition.condition(self, self.context) and
                 checkPermission(transition.permission, self.context)]
 
-    def getManualTransitionIdsToward(self, state):
+    def getSystemTransitionIds(self):
+        # ignore permission checks
+        return [transition.transition_id for transition in
+                sorted(self._getTransitions(SYSTEM)) if
+                transition.condition(self, self.context)]
+
+    def getFireableTransitionIds(self):
+        return self.getManualTransitionIds() + self.getSystemTransitionIds()
+    
+    def getFireableTransitionIdsToward(self, state):
         wf = zapi.getUtility(IWorkflow)
         result = []
-        for transition_id in self.getManualTransitionIds():
+        for transition_id in self.getFireableTransitionIds():
             transition = wf.getTransitionById(transition_id)
             if transition.destination == state:
                 result.append(transition_id)
         return result
-            
+    
     def getAutomaticTransitionIds(self):
         return [transition.transition_id for transition in
                 self._getTransitions(AUTOMATIC)]

Modified: z3/hurry/trunk/src/hurry/workflow/workflow.txt
==============================================================================
--- z3/hurry/trunk/src/hurry/workflow/workflow.txt	(original)
+++ z3/hurry/trunk/src/hurry/workflow/workflow.txt	Wed Sep 28 19:22:37 2005
@@ -69,9 +69,10 @@
     ...     action=NullAction, 
     ...     trigger=interfaces.MANUAL)
 
-The transition trigger is either MANUAL or AUTOMATIC. MANUAL indicates
-user action is needed to fire the transition; AUTOMATIC transitions
-fire automatically.
+The transition trigger is either MANUAL, AUTOMATIC or SYSTEM. MANUAL
+indicates user action is needed to fire the transition. AUTOMATIC
+transitions fire automatically. SYSTEM is a workflow transition
+directly fired by the system, and not directly by the user.
 
 We also will introduce an initial transition, that moves an object
 into the workflow (for instance just after it is created)::
@@ -130,10 +131,10 @@
     >>> info.getManualTransitionIds()
     ['a_to_b']
 
-We can also get this by asking which manual transition exists that brings
-us to the desired workflow state::
+We can also get this by asking which manual (or system) transition
+exists that brings us to the desired workflow state::
 
-    >>> info.getManualTransitionIdsToward('b')
+    >>> info.getFireableTransitionIdsToward('b')
     ['a_to_b']
 
 Since this is a manually triggered transition, we can fire this
@@ -515,6 +516,59 @@
    >>> state.getState()
    'published'
 
+System transitions
+------------------
+
+Let's try system transitions now. This transition shouldn't show up
+as manual nor as automatic::
+
+   >>> publish_transition = workflow.Transition(
+   ...    transition_id='publish',
+   ...    title='Publish',
+   ...    source=UNPUBLISHED,
+   ...    destination=PUBLISHED,
+   ...    trigger=interfaces.SYSTEM)
+
+Set up the workflow using this transition, and reusing the
+init transition we defined before::
+
+   >>> wf = workflow.Workflow([init_transition, publish_transition])
+   >>> ztapi.provideUtility(interfaces.IWorkflow, wf)
+
+Clear out all versions; this is an private API we just use for
+demonstration purposes::
+
+   >>> workflow_versions.clear()
+
+Now create a document::
+
+   >>> document = Document('bar')
+   >>> info = interfaces.IWorkflowInfo(document)
+   >>> info.fireTransition('init')
+
+Private again; do this with the catalog or any way you prefer in your
+own code::
+
+   >>> workflow_versions.addVersion(document)
+
+We should see it as a system transition::
+
+   >>> info.getSystemTransitionIds()
+   ['publish']
+
+but not as automatic nor manual::
+
+   >>> info.getAutomaticTransitionIds()
+   []
+   >>> info.getManualTransitionIds()
+   []
+
+This transition can be fired::
+
+   >>> info.fireTransition('publish')
+   >>> interfaces.IWorkflowState(document).getState()
+   'published'
+
 Multiple transitions
 --------------------
 


More information about the z3-checkins mailing list