Commit 00aa62f6 authored by iv's avatar iv

ERP5Workflow: minor improvements

improve for loop, call less time the same method, ...
parent c43e12ff
......@@ -113,7 +113,8 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
instead of getting all the transition objects from the destination list
to then use their ids, extract the information from the string
"""
return [path.split('/')[-1] for path in self.getDestinationList()]
return [path.split('/')[-1] for path in self.getCategoryList()
if path.startswith('destination/')]
security.declareProtected(Permissions.AccessContentsInformation,
'getDestinationValueList')
......
......@@ -257,18 +257,19 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
state = self._getWorkflowStateOf(ob)
tool = aq_parent(aq_inner(self))
other_workflow_list = [x for x in tool.getWorkflowsFor(ob)
if x.id != self.id and x.getPortalType() in
('DCWorkflowDefinition', 'Workflow')]
other_data_list = []
new_permission_roles_dict = {}
for other_workflow in other_workflow_list:
for other_workflow in tool.getWorkflowsFor(ob):
if other_workflow.id == self.id or other_workflow.getPortalType() in \
('DCWorkflowDefinition', 'Workflow'):
continue
other_state = other_workflow._getWorkflowStateOf(ob)
if other_state is not None:
other_state_permission_roles_dict = other_state.getStatePermissionRolesDict()
if other_state_permission_roles_dict is not None:
other_data_list.append((other_workflow,other_state))
other_data_list.append((other_workflow, other_state,
other_state_permission_roles_dict))
# Be carefull, permissions_roles should not change
# from list to tuple or vice-versa. (in modifyRolesForPermission,
# list means acquire roles, tuple means do not acquire)
......@@ -284,9 +285,9 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
roles = list(roles)
# We will check that each role is activated
# in each DCWorkflow
for other_workflow, other_state in other_data_list:
for other_workflow, other_state, other_state_permission_roles_dict in other_data_list:
if p in other_workflow.workflow_managed_permission:
other_roles = other_state.getStatePermissionRolesDict().get(p, [])
other_roles = other_state_permission_roles_dict.get(p, [])
other_role_type_list.append(type(other_roles))
for role in roles:
if role not in other_roles:
......@@ -722,7 +723,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
new_state = old_state
else:
new_state = new_sdef.getReference()
former_status = self.getCurrentStatusDict(document)
former_status = status_dict
# Execute the "before" script.
before_script_success = 1
......@@ -1165,7 +1166,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject, CacheCookieMixin):
# Figure out the old and new states.
old_sdef = self._getWorkflowStateOf(ob)
if old_sdef is None:
old_state = self._getWorkflowStateOf(ob, id_only=True)
old_state = state.getReference()
else:
old_state = old_sdef.getId()
if old_state == new_state_id:
......
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