Commit 07a53d06 authored by Nicolas Delaby's avatar Nicolas Delaby

Add new Interaction Executing Type: Before Commit

this Executing Type allow to execute a interaction script at the end of transaction


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24180 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7f7c2d49
...@@ -54,6 +54,7 @@ class InteractionDefinition (SimpleItem): ...@@ -54,6 +54,7 @@ class InteractionDefinition (SimpleItem):
var_exprs = None # A mapping. var_exprs = None # A mapping.
script_name = () # Executed before transition script_name = () # Executed before transition
after_script_name = () # Executed after transition after_script_name = () # Executed after transition
before_commit_script_name = () #Executed Before Commit Transaction
activate_script_name = () # Executed as activity activate_script_name = () # Executed as activity
method_id = () method_id = ()
portal_type_filter = None portal_type_filter = None
...@@ -120,6 +121,7 @@ class InteractionDefinition (SimpleItem): ...@@ -120,6 +121,7 @@ class InteractionDefinition (SimpleItem):
once_per_transaction=False, once_per_transaction=False,
script_name=(), script_name=(),
after_script_name=(), after_script_name=(),
before_commit_script_name=(),
activate_script_name=(), activate_script_name=(),
actbox_name='', actbox_url='', actbox_name='', actbox_url='',
actbox_category='workflow', actbox_category='workflow',
...@@ -149,6 +151,7 @@ class InteractionDefinition (SimpleItem): ...@@ -149,6 +151,7 @@ class InteractionDefinition (SimpleItem):
self.once_per_transaction = bool(once_per_transaction) self.once_per_transaction = bool(once_per_transaction)
self.script_name = script_name self.script_name = script_name
self.after_script_name = after_script_name self.after_script_name = after_script_name
self.before_commit_script_name = before_commit_script_name
self.activate_script_name = activate_script_name self.activate_script_name = activate_script_name
g = Guard() g = Guard()
if g.changeFromProperties(props or REQUEST): if g.changeFromProperties(props or REQUEST):
......
...@@ -301,20 +301,27 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject): ...@@ -301,20 +301,27 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject):
ob, self, former_status, tdef, None, None, kwargs=kw) ob, self, former_status, tdef, None, None, kwargs=kw)
script(sci) # May throw an exception script(sci) # May throw an exception
# Execute Before Commit
for script_name in tdef.before_commit_script_name:
method = getattr(self, 'activeScript')
get_transaction().beforeCommitHook(method, script_name,
ob.getRelativeUrl(),
status, tdef.id, kw)
# Execute "activity" scripts # Execute "activity" scripts
for script_name in tdef.activate_script_name: for script_name in tdef.activate_script_name:
self.activate(activity='SQLQueue')\ self.activate(activity='SQLQueue')\
.activeScript(script_name, ob.getRelativeUrl(), status, tdef.id) .activeScript(script_name, ob.getRelativeUrl(), status, tdef.id)
security.declarePrivate('activeScript') security.declarePrivate('activeScript')
def activeScript(self, script_name, ob_url, status, tdef_id): def activeScript(self, script_name, ob_url, status, tdef_id, kwargs=None):
script = self.scripts[script_name] script = self.scripts[script_name]
ob = self.unrestrictedTraverse(ob_url) ob = self.unrestrictedTraverse(ob_url)
tdef = self.interactions.get(tdef_id) tdef = self.interactions.get(tdef_id)
sci = StateChangeInfo( sci = StateChangeInfo(
ob, self, status, tdef, None, None, None) ob, self, status, tdef, None, None, kwargs)
script(sci) script(sci)
def _getWorkflowStateOf(self, ob, id_only=0): def _getWorkflowStateOf(self, ob, id_only=0):
return None return None
......
...@@ -81,6 +81,20 @@ ...@@ -81,6 +81,20 @@
</td> </td>
</tr> </tr>
<tr>
<th align="left">Script (end of transaction)</th>
<td>
<select name="before_commit_script_name:list" multiple size="5">
<option value="None">(None)</option>
<dtml-in getAvailableScriptIds sort>
<dtml-let selected="_['sequence-item'] in before_commit_script_name and 'selected' or ' '">
<option value="&dtml-sequence-item;" &dtml-selected;>&dtml-sequence-item;</option>
</dtml-let>
</dtml-in>
</select>
</td>
</tr>
<tr> <tr>
<th align="left">Activities (later)</th> <th align="left">Activities (later)</th>
<td> <td>
......
...@@ -81,13 +81,16 @@ class TestInteractionWorkflow(ERP5TypeTestCase): ...@@ -81,13 +81,16 @@ class TestInteractionWorkflow(ERP5TypeTestCase):
def createInteractionWorkflow(self): def createInteractionWorkflow(self):
id = 'test_workflow' id = 'test_workflow'
wf_type = "interaction_workflow (Web-configurable interaction workflow)" wf_type = "interaction_workflow (Web-configurable interaction workflow)"
self.getWorkflowTool().manage_addWorkflow(workflow_type=wf_type,id=id) if getattr(self.getWorkflowTool(), id, None) is None:
self.getWorkflowTool().manage_addWorkflow(workflow_type=wf_type,id=id)
wf = self.getWorkflowTool()[id] wf = self.getWorkflowTool()[id]
self.wf = wf self.wf = wf
wf.scripts.manage_addProduct['PythonScripts']\ if getattr(wf.scripts, 'afterEdit', None) is None:
.manage_addPythonScript(id='afterEdit') wf.scripts.manage_addProduct['PythonScripts']\
.manage_addPythonScript(id='afterEdit')
self.script = wf.scripts['afterEdit'] self.script = wf.scripts['afterEdit']
wf.interactions.addInteraction(id='edit_interaction') if getattr(wf.interactions, 'edit_interaction', None) is None:
wf.interactions.addInteraction(id='edit_interaction')
self.interaction = wf.interactions['edit_interaction'] self.interaction = wf.interactions['edit_interaction']
self.getWorkflowTool().setChainForPortalTypes( self.getWorkflowTool().setChainForPortalTypes(
[self.portal_type],'test_workflow, validation_workflow') [self.portal_type],'test_workflow, validation_workflow')
...@@ -496,6 +499,34 @@ context.setDescription('%s,%s,%s' % (d, args, result)) ...@@ -496,6 +499,34 @@ context.setDescription('%s,%s,%s' % (d, args, result))
value = organisation.getDescription() value = organisation.getDescription()
self.assertEquals(value, "toto,('description',),bad") self.assertEquals(value, "toto,('description',),bad")
def test_16_BeforeCommitParameters(self, quiet=0, run=run_all_test):
if not run: return
if not quiet:
self.logMessage('Before Commit Script Parameters')
self.createInteractionWorkflow()
self.interaction.setProperties(
'beforeCommit',
method_id='getProperty',
before_commit_script_name=('afterEdit',))
params = 'sci, **kw'
body = """\
context = sci['object']
kwargs = sci['kwargs'] or {}
d = kwargs.get('d', None)
args = kwargs.get('workflow_method_args', ())
result = kwargs.get('workflow_method_result', None)
context.setDescription('%s,%s,%s' % (d, args, result))
"""
self.script.ZPythonScript_edit(params, body)
self.createData()
organisation = self.organisation
organisation.setDescription('bad')
self.assertEquals(organisation.getDescription(), 'bad')
organisation.getProperty('description', d='toto')
self.assertEquals(organisation.getDescription(), 'bad')
get_transaction().commit()
self.assertEquals(organisation.getDescription(), "toto,('description',),bad")
def test_regular_expression(self): def test_regular_expression(self):
# test that we can add an interaction by defining methods using regular # test that we can add an interaction by defining methods using regular
# expression # expression
......
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