[workflow] add method on IWorkflowable to set initial state of an entity (closes #1686357)
--- a/entities/wfobjs.py Thu May 19 10:35:20 2011 +0200
+++ b/entities/wfobjs.py Thu May 19 15:56:49 2011 +0200
@@ -595,7 +595,7 @@
stateeid = statename.eid
else:
if not isinstance(statename, basestring):
- warn('[3.5] give a state name', DeprecationWarning)
+ warn('[3.5] give a state name', DeprecationWarning, stacklevel=2)
state = self.current_workflow.state_by_eid(statename)
else:
state = self.current_workflow.state_by_name(statename)
@@ -605,3 +605,20 @@
stateeid = state.eid
# XXX try to find matching transition?
return self._add_trinfo(comment, commentformat, tr and tr.eid, stateeid)
+
+ def set_initial_state(self, statename):
+ """set a newly created entity's state to the given state (name or entity)
+ in entity's workflow. This is useful if you don't want it to be the
+ workflow's initial state.
+ """
+ assert self.current_workflow
+ if hasattr(statename, 'eid'):
+ stateeid = statename.eid
+ else:
+ state = self.current_workflow.state_by_name(statename)
+ if state is None:
+ raise WorkflowException('not a %s state: %s' % (self.__regid__,
+ statename))
+ stateeid = state.eid
+ self._cw.execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s',
+ {'x': self.entity.eid, 's': stateeid})