Commit 4ad919d3 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Workflow action may not be available yet, thus provide a way to try again



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@46003 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent adef573c
...@@ -742,6 +742,8 @@ class MainForm(Form): ...@@ -742,6 +742,8 @@ class MainForm(Form):
""" """
self.submitSelectFavourite(value='/logout') self.submitSelectFavourite(value='/logout')
import time
class ContextMainForm(MainForm): class ContextMainForm(MainForm):
""" """
Class defining context-dependent convenient methods for the main Class defining context-dependent convenient methods for the main
...@@ -845,7 +847,9 @@ class ContextMainForm(MainForm): ...@@ -845,7 +847,9 @@ class ContextMainForm(MainForm):
self.submit(name='Base_doSelect:method') self.submit(name='Base_doSelect:method')
def submitSelectWorkflow(self, label=None, value=None, def submitSelectWorkflow(self, label=None, value=None,
script_id='viewWorkflowActionDialog', **kw): script_id='viewWorkflowActionDialog',
maximum_attempt_number=1, sleep_between_attempt=0,
**kw):
""" """
Select and submit a workflow action, given either by its label Select and submit a workflow action, given either by its label
(such as I{Create User}) or value (such as I{create_user_action} (such as I{Create User}) or value (such as I{create_user_action}
...@@ -855,9 +859,21 @@ class ContextMainForm(MainForm): ...@@ -855,9 +859,21 @@ class ContextMainForm(MainForm):
When validating an object, L{submitDialogConfirm} allows to When validating an object, L{submitDialogConfirm} allows to
perform the validation required on the next page. perform the validation required on the next page.
As the Workflow action may not be available yet, it is possible to set the
maximum number of attempts and the sleep duration between each attempt.
@param script_id: Script identifier @param script_id: Script identifier
@type script_id: str @type script_id: str
@param maximum_attempt_number: Number of attempts before failing
@type maximum_attempt_number: int
@param sleep_between_attempt: Sleep N seconds between attempts
@type sleep_between_attempt: int
@return: The time spent (in seconds) if relevant
@rtype: int
""" """
current_attempt_number = 1
while True:
try:
try: try:
self.submitSelect('select_action', 'Base_doAction:method', label, self.submitSelect('select_action', 'Base_doAction:method', label,
value and '%s?workflow_action=%s' % (script_id, value), value and '%s?workflow_action=%s' % (script_id, value),
...@@ -868,6 +884,16 @@ class ContextMainForm(MainForm): ...@@ -868,6 +884,16 @@ class ContextMainForm(MainForm):
value and '%s?field_my_workflow_action=%s' % (script_id, value and '%s?field_my_workflow_action=%s' % (script_id,
value), value),
**kw) **kw)
except LookupError:
if current_attempt_nbr == maximum_attempt_number:
raise
current_attempt_number += 1
time.sleep(sleep_between_attempt)
else:
break
return (current_attempt_number - 1) * sleep_between_attempt
def submitDialogCancel(self): def submitDialogCancel(self):
""" """
......
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