Commit 8bb1996b authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[workflow] add method on IWorkflowable to set initial state of an entity (closes #1686357)

--HG--
branch : stable
parent 8345ee2c2ea6
......@@ -595,7 +595,7 @@ class IWorkflowableAdapter(WorkflowableMixIn, EntityAdapter):
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 @@ class IWorkflowableAdapter(WorkflowableMixIn, EntityAdapter):
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})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment