From 432a579d47f231c94d14822e27331793d65e4e65 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Mon, 2 Jun 2014 15:08:39 +0200 Subject: [PATCH] [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. --- fields/workflow.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fields/workflow.py b/fields/workflow.py index f0c830c..6dee661 100644 --- a/fields/workflow.py +++ b/fields/workflow.py @@ -358,6 +358,14 @@ class Transition: if msgPart: msg += msgPart 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, doHistory=True, doSay=True, reindex=True, noSecurity=False): '''This method triggers this transition (named p_name) on p_obj. If @@ -400,6 +408,9 @@ class Transition: if not doHistory: comment = '_invisible_' obj.addHistoryEvent(action, review_state=targetStateName, 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 msg = '' if doAction and self.action: msg = self.executeAction(obj, wf)