[gen] On a workflow class, one may now define a method 'onTrigger(self, obj, transitionName)' that will be called after any transition has been triggered, but before the a transition-specific action.

This commit is contained in:
Gaetan Delannay 2014-06-02 15:08:39 +02:00
parent 6494bf22c7
commit 432a579d47

View file

@ -358,6 +358,14 @@ class Transition:
if msgPart: msg += msgPart if msgPart: msg += msgPart
return msg return msg
def executeCommonAction(self, obj, name, wf):
'''Executes the action that is common to any transition, named
"onTrigger" on the workflow class by convention. The common action is
executed before the transition-specific action (if any).'''
obj = obj.appy()
wf = wf.__instance__ # We need the prototypical instance here.
wf.onTrigger(obj, name)
def trigger(self, name, obj, wf, comment, doAction=True, doNotify=True, def trigger(self, name, obj, wf, comment, doAction=True, doNotify=True,
doHistory=True, doSay=True, reindex=True, noSecurity=False): doHistory=True, doSay=True, reindex=True, noSecurity=False):
'''This method triggers this transition (named p_name) on p_obj. If '''This method triggers this transition (named p_name) on p_obj. If
@ -400,6 +408,9 @@ class Transition:
if not doHistory: comment = '_invisible_' if not doHistory: comment = '_invisible_'
obj.addHistoryEvent(action, review_state=targetStateName, obj.addHistoryEvent(action, review_state=targetStateName,
comments=comment) comments=comment)
# Execute the action that is common to all transitions, if defined.
if doAction and hasattr(wf, 'onTrigger'):
self.executeCommonAction(obj, name, wf)
# Execute the related action if needed # Execute the related action if needed
msg = '' msg = ''
if doAction and self.action: msg = self.executeAction(obj, wf) if doAction and self.action: msg = self.executeAction(obj, wf)