# HG changeset patch # User Sylvain Thénault # Date 1305820381 -7200 # Node ID 02a786d7ebce3c747e231f204d08082b55dd2c4a # Parent 344aa07dd0f2b4e4165c809119f0317be9395f1f [workflow] new 'fire_transition_if_possible' method on IWorkflowable to fire a transition if it's possible diff -r 344aa07dd0f2 -r 02a786d7ebce entities/wfobjs.py --- a/entities/wfobjs.py Thu May 19 17:53:00 2011 +0200 +++ b/entities/wfobjs.py Thu May 19 17:53:01 2011 +0200 @@ -572,18 +572,31 @@ kwargs['to_state'] = self._cw.entity_from_eid(tseid) return self._cw.create_entity('TrInfo', **kwargs) - def fire_transition(self, tr, comment=None, commentformat=None): - """change the entity's state by firing transition of the given name in - entity's workflow - """ + def _get_transition(self, tr): assert self.current_workflow if isinstance(tr, basestring): _tr = self.current_workflow.transition_by_name(tr) assert _tr is not None, 'not a %s transition: %s' % ( self.__regid__, tr) tr = _tr + return tr + + def fire_transition(self, tr, comment=None, commentformat=None): + """change the entity's state by firing given transition (name or entity) + in entity's workflow + """ + tr = self._get_transition(tr) return self._add_trinfo(comment, commentformat, tr.eid) + def fire_transition_if_possible(self, tr, comment=None, commentformat=None): + """change the entity's state by firing given transition (name or entity) + in entity's workflow if this transition is possible + """ + tr = self._get_transition(tr) + if any(tr_ for tr_ in self.possible_transitions() + if tr_.eid == tr.eid): + self.fire_transition(tr) + def change_state(self, statename, comment=None, commentformat=None, tr=None): """change the entity's state to the given state (name or entity) in entity's workflow. This method should only by used by manager to fix an