[Erp5-report] r24180 - in /erp5/trunk/products/ERP5: ./ dtml/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Oct 14 18:59:35 CEST 2008
Author: nicolas
Date: Tue Oct 14 18:59:34 2008
New Revision: 24180
URL: http://svn.erp5.org?rev=24180&view=rev
Log:
Add new Interaction Executing Type: Before Commit
this Executing Type allow to execute a interaction script at the end of transaction
Modified:
erp5/trunk/products/ERP5/Interaction.py
erp5/trunk/products/ERP5/InteractionWorkflow.py
erp5/trunk/products/ERP5/dtml/interaction_properties.dtml
erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py
Modified: erp5/trunk/products/ERP5/Interaction.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Interaction.py?rev=24180&r1=24179&r2=24180&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Interaction.py (original)
+++ erp5/trunk/products/ERP5/Interaction.py Tue Oct 14 18:59:34 2008
@@ -54,6 +54,7 @@
var_exprs = None # A mapping.
script_name = () # Executed before transition
after_script_name = () # Executed after transition
+ before_commit_script_name = () #Executed Before Commit Transaction
activate_script_name = () # Executed as activity
method_id = ()
portal_type_filter = None
@@ -120,6 +121,7 @@
once_per_transaction=False,
script_name=(),
after_script_name=(),
+ before_commit_script_name=(),
activate_script_name=(),
actbox_name='', actbox_url='',
actbox_category='workflow',
@@ -149,6 +151,7 @@
self.once_per_transaction = bool(once_per_transaction)
self.script_name = 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
g = Guard()
if g.changeFromProperties(props or REQUEST):
Modified: erp5/trunk/products/ERP5/InteractionWorkflow.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/InteractionWorkflow.py?rev=24180&r1=24179&r2=24180&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/InteractionWorkflow.py (original)
+++ erp5/trunk/products/ERP5/InteractionWorkflow.py Tue Oct 14 18:59:34 2008
@@ -301,20 +301,27 @@
ob, self, former_status, tdef, None, None, kwargs=kw)
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
for script_name in tdef.activate_script_name:
self.activate(activity='SQLQueue')\
.activeScript(script_name, ob.getRelativeUrl(), status, tdef.id)
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]
ob = self.unrestrictedTraverse(ob_url)
tdef = self.interactions.get(tdef_id)
sci = StateChangeInfo(
- ob, self, status, tdef, None, None, None)
+ ob, self, status, tdef, None, None, kwargs)
script(sci)
-
+
def _getWorkflowStateOf(self, ob, id_only=0):
return None
Modified: erp5/trunk/products/ERP5/dtml/interaction_properties.dtml
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/dtml/interaction_properties.dtml?rev=24180&r1=24179&r2=24180&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/dtml/interaction_properties.dtml (original)
+++ erp5/trunk/products/ERP5/dtml/interaction_properties.dtml Tue Oct 14 18:59:34 2008
@@ -82,6 +82,20 @@
</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>
<th align="left">Activities (later)</th>
<td>
<select name="activate_script_name:list" multiple size="5">
Modified: erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py?rev=24180&r1=24179&r2=24180&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py (original)
+++ erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py Tue Oct 14 18:59:34 2008
@@ -81,13 +81,16 @@
def createInteractionWorkflow(self):
id = 'test_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]
self.wf = wf
- wf.scripts.manage_addProduct['PythonScripts']\
- .manage_addPythonScript(id='afterEdit')
+ if getattr(wf.scripts, 'afterEdit', None) is None:
+ wf.scripts.manage_addProduct['PythonScripts']\
+ .manage_addPythonScript(id='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.getWorkflowTool().setChainForPortalTypes(
[self.portal_type],'test_workflow, validation_workflow')
@@ -496,6 +499,34 @@
value = organisation.getDescription()
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):
# test that we can add an interaction by defining methods using regular
# expression
More information about the Erp5-report
mailing list