Commit 4a3f3be4 authored by iv's avatar iv

ERP5Workflow: add method to get transition/script id by reference

in order to remove hardcoded 'transition_' or 'script_'
parent bea4e3d4
......@@ -822,6 +822,8 @@ def DCWorkflowDefinition_getTransitionValueList(self):
return self.transitions.values()
else:
return []
def DCWorkflowDefinition_getTransitionIdByReference(self, reference):
return reference
def DCWorkflowDefinition_getTransitionIdList(self):
if self.transitions is not None:
return self.transitions.objectIds()
......@@ -840,6 +842,8 @@ def DCWorkflowDefinition_getWorklistIdList(self):
return []
def DCWorkflowDefinition_propertyIds(self):
return sorted(self.__dict__.keys())
def DCWorkflowDefinition_getScriptIdByReference(self, reference):
return reference
def DCWorkflowDefinition_getScriptValueList(self):
if self.scripts is not None:
return self.scripts.values()
......@@ -1122,6 +1126,8 @@ DCWorkflowDefinition.showDict = DCWorkflowDefinition_showDict
DCWorkflowDefinition.propertyIds = DCWorkflowDefinition_propertyIds
DCWorkflowDefinition.getStateVariable = DCWorkflowDefinition_getStateVariable
DCWorkflowDefinition.getPortalType = DCWorkflowDefinition_getPortalType
DCWorkflowDefinition.getScriptIdByReference = DCWorkflowDefinition_getScriptIdByReference
DCWorkflowDefinition.getTransitionIdByReference = DCWorkflowDefinition_getTransitionIdByReference
StateDefinition.getReference = method_getReference
StateDefinition.getDestinationIdList = StateDefinition_getDestinationIdList
StateDefinition.getDestinationReferenceList = StateDefinition_getDestinationIdList
......
......@@ -549,6 +549,12 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
return [worklist.getReference()
for worklist in self.objectValues(portal_type="Worklist")]
def getTransitionIdByReference(self, transition_reference):
return 'transition_' + transition_reference
def getScriptIdByReference(self, script_reference):
return 'script_' + script_reference
def getWorklistValueById(self, worklist_reference):
return self._getOb('worklist_' + worklist_reference, None)
......
......@@ -199,7 +199,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
found = 0
for workflow in workflow_list:
if workflow.getPortalType() == 'Workflow':
action_id = 'transition_' + action_reference
action_id = workflow.getTransitionIdByReference(action_reference)
if workflow.isActionSupported(current_object, action_id, **kw):
found = 1
break
......@@ -211,7 +211,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
if workflow is None:
raise WorkflowException(_(u'Requested workflow definition not found.'))
if workflow.getPortalType() == 'Workflow':
action_id = 'transition_' + action_reference
action_id = workflow.getTransitionIdByReference(action_reference)
result = self._invokeWithNotification(
workflow_list, current_object, action_id, workflow.doActionFor,
(current_object, action_id) + args, kw)
......@@ -290,8 +290,8 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
initial_script_name_list = [initial_script_name_list]
for script_name in initial_script_name_list:
if script_name:
script = getattr(workflow, 'script_' + script_name, None) or \
getattr(workflow, 'transition_' + script_name, None)
script = getattr(workflow, workflow.getScriptIdByReference(script_name), None) or \
getattr(workflow, workflow.getTransitionIdByReference(script_name), None)
script_path = script.getRelativeUrl()
script_path_list.append(script_path)
return script_path_list
......@@ -333,7 +333,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
for script_id in dc_workflow_script_list:
script = dc_workflow_script_list.get(script_id)
# add a prefix if there is a script & method conflict
workflow_script = workflow.newContent(id='script_' + script_id,
workflow_script = workflow.newContent(id=workflow.getScriptIdByReference(script_id),
portal_type='Workflow Script',
temp_object=is_temporary)
workflow_script.setTitle(script.title)
......@@ -428,7 +428,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
sdef.addPossibleTransition(transition_id)
# set transition's destination state:
for tid in dc_workflow_transition_value_list:
tdef = workflow._getOb('transition_'+tid)
tdef = workflow.getTransitionValueById(tid)
state = getattr(workflow, 'state_'+dc_workflow_transition_value_list.get(tid).new_state_id, None)
if state is None:
# it's a remain in state transition.
......@@ -563,7 +563,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
dc_workflow_transition_value_list = dc_workflow.transitions
for tid in dc_workflow_transition_value_list:
origin_tdef = dc_workflow_transition_value_list[tid]
transition = workflow._getOb('transition_'+tid)
transition = workflow.getTransitionValueById(tid)
new_category = []
if origin_tdef.var_exprs is None:
var_exprs = {}
......
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