Commit e793b164 authored by Vincent Pelletier's avatar Vincent Pelletier

DCWorkflowDefinition_listObjectActions: Always return a vector.

Simplifies callers, as they then do not have to test for None.
Also, use sort(key=...), which removes the need for internal 2-tuple
wrapping & unwrapping of all result entries.
Also, coding style (helps line-based profiling readability) & better
naming.
parent bba23043
...@@ -225,31 +225,36 @@ def DCWorkflowDefinition_listObjectActions(self, info): ...@@ -225,31 +225,36 @@ def DCWorkflowDefinition_listObjectActions(self, info):
info.object. info.object.
Returns the actions to be displayed to the user. Returns the actions to be displayed to the user.
''' '''
fmt_data = None
ob = info.object ob = info.object
sdef = self._getWorkflowStateOf(ob) sdef = self._getWorkflowStateOf(ob)
if sdef is None: if sdef is None:
return None return ()
res = [] fmt_data = None
for tid in sdef.transitions: result = []
tdef = self.transitions.get(tid, None) for transition_id in sdef.transitions:
if tdef is not None and tdef.trigger_type == TRIGGER_USER_ACTION and \ tdef = self.transitions.get(transition_id)
tdef.actbox_name and self._checkTransitionGuard(tdef, ob): if (
tdef is not None and
tdef.trigger_type == TRIGGER_USER_ACTION and
tdef.actbox_name and
self._checkTransitionGuard(tdef, ob)
):
if fmt_data is None: if fmt_data is None:
fmt_data = TemplateDict() fmt_data = TemplateDict()
fmt_data._push(info) fmt_data._push(info)
fmt_data._push({'transition_id': tid}) fmt_data._push({'transition_id': transition_id})
res.append((tid, { result.append({
'id': tid, 'id': transition_id,
'name': tdef.actbox_name % fmt_data, 'name': tdef.actbox_name % fmt_data,
'url': tdef.actbox_url % fmt_data, 'url': tdef.actbox_url % fmt_data,
'icon': tdef.actbox_icon % fmt_data, 'icon': tdef.actbox_icon % fmt_data,
'permissions': (), # Predetermined. 'permissions': (), # Predetermined.
'category': tdef.actbox_category, 'category': tdef.actbox_category,
'transition': tdef})) 'transition': tdef,
})
fmt_data._pop() fmt_data._pop()
res.sort() result.sort(key=lambda x: x['id'])
return [ result[1] for result in res ] return result
DCWorkflowDefinition.listObjectActions = DCWorkflowDefinition_listObjectActions DCWorkflowDefinition.listObjectActions = DCWorkflowDefinition_listObjectActions
from Products.DCWorkflow.Expression import Expression from Products.DCWorkflow.Expression import Expression
......
...@@ -461,9 +461,7 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False): ...@@ -461,9 +461,7 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False):
for wf_id in self.getChainFor(info.object): for wf_id in self.getChainFor(info.object):
wf = self.getWorkflowById(wf_id) wf = self.getWorkflowById(wf_id)
if wf is not None: if wf is not None:
a = wf.listObjectActions(info) actions.extend(wf.listObjectActions(info))
if a is not None:
actions.extend(a)
portal = self.getPortalObject() portal = self.getPortalObject()
portal_url = portal.portal_url() portal_url = portal.portal_url()
......
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