entities/wfobjs.py
changeset 3998 94cc7cad3d2d
parent 3777 3ef8cdb5fb1c
parent 3986 cc29eddf51ad
child 4012 f6c65e04704c
--- a/entities/wfobjs.py	Mon Nov 23 14:13:53 2009 +0100
+++ b/entities/wfobjs.py	Thu Dec 03 17:17:43 2009 +0100
@@ -34,6 +34,7 @@
         return any(et for et in self.reverse_default_workflow
                    if et.name == etype)
 
+    # XXX define parent() instead? what if workflow of multiple types?
     def after_deletion_path(self):
         """return (path, parameters) which should be used as redirect
         information when this entity is being deleted
@@ -101,7 +102,7 @@
         self._cw.execute('SET S state_of WF WHERE S eid %(s)s, WF eid %(wf)s',
                          {'s': state.eid, 'wf': self.eid}, ('s', 'wf'))
         if initial:
-            assert not self.initial
+            assert not self.initial, "Initial state already defined as %s" % self.initial
             self._cw.execute('SET WF initial_state S '
                              'WHERE S eid %(s)s, WF eid %(wf)s',
                              {'s': state.eid, 'wf': self.eid}, ('s', 'wf'))
@@ -245,6 +246,9 @@
     def destination(self):
         return self.destination_state[0]
 
+    def parent(self):
+        return self.workflow
+
 
 class WorkflowTransition(BaseTransition):
     """customized class for WorkflowTransition entities"""
@@ -310,6 +314,9 @@
     def destination(self):
         return self.destination_state and self.destination_state[0] or None
 
+    def parent(self):
+        return self.reverse_subworkflow_exit[0]
+
 
 class State(AnyEntity):
     """customized class for State entities"""
@@ -322,13 +329,8 @@
         # take care, may be missing in multi-sources configuration
         return self.state_of and self.state_of[0]
 
-    def after_deletion_path(self):
-        """return (path, parameters) which should be used as redirect
-        information when this entity is being deleted
-        """
-        if self.state_of:
-            return self.state_of[0].rest_path(), {}
-        return super(State, self).after_deletion_path()
+    def parent(self):
+        return self.workflow
 
 
 class TrInfo(AnyEntity):
@@ -353,13 +355,8 @@
     def transition(self):
         return self.by_transition and self.by_transition[0] or None
 
-    def after_deletion_path(self):
-        """return (path, parameters) which should be used as redirect
-        information when this entity is being deleted
-        """
-        if self.for_entity:
-            return self.for_entity.rest_path(), {}
-        return 'view', {}
+    def parent(self):
+        return self.for_entity
 
 
 class WorkflowableMixIn(object):
@@ -431,6 +428,7 @@
     def possible_transitions(self, type='normal'):
         """generates transition that MAY be fired for the given entity,
         expected to be in this state
+        used only by the UI
         """
         if self.current_state is None or self.current_workflow is None:
             return