[hal_json] Add new Portal Action "Mass Workflow Change"
Showing
"""Base_getFormIdForWorkflowAction returns form_id of a form (dialog) used by `workflow_action` | |||
This is not an UI script - it should be used in TALES expressions or called internally. | |||
Developer Notes: | |||
Format of Action returned by getFilteredActions['workflow'] = [{ | |||
'available': True, | |||
'visible': True, | |||
'allowed': True, | |||
'link_target': None, | |||
'id': 'invalidate_action', | |||
'category': 'workflow', | |||
'name': 'Invalidate Action', | |||
'title': 'Invalidate Action', | |||
'url': 'https://softinst81338.host.vifib.net/erp5/web_site_module/renderjs_runner/foo_module/27/Base_viewWorkflowActionDialog?workflow_action=invalidate_action', | |||
|
|||
'transition': <TransitionDefinition at /erp5/portal_workflow/foo_workflow/id_form_dict/invalidate_action>, | |||
'icon': ''}, ... ] | |||
""" | |||
action_tool = context.getPortalObject().portal_actions | |||
id_form_dict = dict() | |||
context.log("called with form_id {}, query {}, workflow_action {}".format(form_id, query, workflow_action)) | |||
for result in context.Base_searchUsingFormIdAndQuery(form_id, query): | |||
for action in action_tool.listFilteredActionsFor(result.getObject()).get('workflow', []): | |||
id_form_dict[action['id']] = action['url'].rsplit('/', 1)[1].split('?')[0] | |||
if not workflow_action and len(id_form_dict) == 1: | |||
# if we have only one possible workflow transition we suppose it is the default one | |||
return id_form_dict.items()[0][1] | |||
if workflow_action in id_form_dict: | |||
# if the workflow_action is done and we found it then return related form dialog | |||
return id_form_dict[workflow_action] | |||
# if we have no idea what workflow form we should use - just use ~~the default one~~ nothing | |||
return "" |
"""Return items (ready to be used in listbox of listfield) of common workflows on documents defined by `form_id` and `query`. | |||
:param form_id: {str} Form.ID of a form containing listbox to execute the query | |||
:param query: {str} fulltext query | |||
:param add_empty: {bool} First choice is empty | |||
Developer Notes: | |||
Format of Action returned by getFilteredActions['workflow'] = [{ | |||
'available': True, | |||
'visible': True, | |||
'allowed': True, | |||
'link_target': None, | |||
'id': 'invalidate_action', | |||
'category': 'workflow', | |||
'name': 'Invalidate Action', | |||
'title': 'Invalidate Action', | |||
'url': 'https://softinst81338.host.vifib.net/erp5/web_site_module/renderjs_runner/foo_module/27/Base_viewWorkflowActionDialog?workflow_action=invalidate_action', | |||
|
|||
'transition': <TransitionDefinition at /erp5/portal_workflow/foo_workflow/transition_dict/invalidate_action>, | |||
'icon': ''}, ... ] | |||
""" | |||
def formatDict(d, padding=0): | |||
if not isinstance(d, dict): | |||
return " " * padding + str(d) | |||
return "\n".join(" " * padding + key + ":" + formatDict(d[key], padding+4) for key in d) | |||
action_tool = context.getPortalObject().portal_actions | |||
translate = context.getPortalObject().Base_translateString | |||
workflow_list = [] | |||
if add_empty: | |||
workflow_list.append((translate('Choose desired action.'), '')) | |||
transition_dict = {} | |||
for result in context.Base_searchUsingFormIdAndQuery(form_id, query): | |||
for action in action_tool.listFilteredActionsFor(result.getObject()).get('workflow', []): | |||
transition_dict[action['id']] = action['title'] | |||
if not transition_dict: | |||
workflow_list.append((translate("No state change possible"), "")) | |||
if len(transition_dict) == 1: | |||
workflow_list = [] # if there is only one workflow possible - do not bother with an empty option | |||
# transition_dict.items() is in form (id, title) but ERP5 requires (title, id) so we reverse | |||
if transition_dict: | |||
workflow_list.extend((title, id) for id, title in sorted(transition_dict.items(), key=lambda x: x[1])) | |||
return workflow_list |
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.