Commit 0e2ed43f authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[erp5_core] Update code of Mass Workflow Transition for performance

parent 7cccbe9d
...@@ -20,17 +20,22 @@ Format of Action returned by getFilteredActions['workflow'] = [{ ...@@ -20,17 +20,22 @@ Format of Action returned by getFilteredActions['workflow'] = [{
action_tool = context.getPortalObject().portal_actions action_tool = context.getPortalObject().portal_actions
id_form_dict = dict() id_form_dict = dict()
for result in context.Base_searchUsingFormIdAndQuery(form_id, query): result_list = ()
if uids is not None:
result_list = context.getPortalObject().portal_catalog(uid=uids)
else:
result_list = context.Base_searchUsingFormIdAndQuery(form_id, query)
for result in result_list:
for action in action_tool.listFilteredActionsFor(result.getObject()).get('workflow', []): for action in action_tool.listFilteredActionsFor(result.getObject()).get('workflow', []):
id_form_dict[action['id']] = action['url'].rsplit('/', 1)[1].split('?')[0] action_form_id = action['url'].rsplit('/', 1)[1].split('?')[0]
id_form_dict[action['id']] = action_form_id
if workflow_action == action['id']:
return action_form_id # early return for performance reasons
if not workflow_action and len(id_form_dict) == 1: 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 # if we have only one possible workflow transition we suppose it is the default one
return id_form_dict.items()[0][1] 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 # if we have no idea what workflow form we should use - just use ~~the default one~~ nothing
return "" return ""
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>form_id, query, workflow_action=\'\'</string> </value> <value> <string>form_id, query=\'\', workflow_action=\'\', uids=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -6,6 +6,7 @@ This script should be used to detect a listbox without having to name it "listbo ...@@ -6,6 +6,7 @@ This script should be used to detect a listbox without having to name it "listbo
Christophe Dumez <christophe@nexedi.com> Christophe Dumez <christophe@nexedi.com>
""" """
from Products.ERP5Type.Log import log, ERROR
def isListBox(field): def isListBox(field):
if field.meta_type == "ListBox": if field.meta_type == "ListBox":
...@@ -19,7 +20,11 @@ def isListBox(field): ...@@ -19,7 +20,11 @@ def isListBox(field):
if form_or_id is None: if form_or_id is None:
form = context form = context
elif isinstance(form_or_id, str): elif isinstance(form_or_id, str):
try:
form = getattr(context, form_or_id) form = getattr(context, form_or_id)
except AttributeError:
log("Form '{}' does not exist!", level=ERROR)
return None
else: else:
form = form_or_id form = form_or_id
......
...@@ -8,18 +8,18 @@ Returns an iterable (most likely SearchResult instance depending on list_method ...@@ -8,18 +8,18 @@ Returns an iterable (most likely SearchResult instance depending on list_method
list_method_kwargs = dict(listbox.get_value('default_params')) or {} list_method_kwargs = dict(listbox.get_value('default_params')) or {}
# Listbox contraints portal types # Listbox contraints portal types
portal_types = listbox.get_value('portal_types') if portal_types is not None:
if portal_types: list_method_kwargs.update(portal_types=portal_types)
else:
if "portal_type" in list_method_kwargs: if "portal_type" in list_method_kwargs:
if isinstance(list_method_kwargs['portal_type'], (str, unicode)): if isinstance(list_method_kwargs['portal_type'], str):
list_method_kwargs['portal_type'] = [list_method_kwargs['portal_type'], ] list_method_kwargs['portal_type'] = [list_method_kwargs['portal_type'], ]
else: elif listbox.get_value("portal_types"):
list_method_kwargs['portal_type'] = [] list_method_kwargs['portal_type'] = [portal_type_name for portal_type_name, _ in listbox.get_value("portal_types")]
list_method_kwargs['portal_type'].extend(portal_type_name for portal_type_name, _ in portal_types)
# query is provided by the caller because it is a runtime information # query is provided by the caller because it is a runtime information
if query: if query or full_text:
list_method_kwargs.update(full_text=query) # second overwrite the query list_method_kwargs.update(full_text=query or full_text) # second overwrite the query
if limit: if limit:
list_method_kwargs.update(limit=limit) list_method_kwargs.update(limit=limit)
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>listbox, query=\'\', sort_on=(), limit=None</string> </value> <value> <string>listbox, query=\'\', full_text=\'\', sort_on=(), limit=None, portal_types=None, **kwargs</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -9,6 +9,8 @@ This script is intended as a dialog target. ...@@ -9,6 +9,8 @@ This script is intended as a dialog target.
""" """
from Products.CMFCore.WorkflowCore import WorkflowException from Products.CMFCore.WorkflowCore import WorkflowException
MARKER = []
portal = context.getPortalObject() portal = context.getPortalObject()
request = kwargs.get("REQUEST", None) or context.REQUEST request = kwargs.get("REQUEST", None) or context.REQUEST
translate = portal.Base_translateString translate = portal.Base_translateString
...@@ -27,7 +29,24 @@ if not workflow_action: ...@@ -27,7 +29,24 @@ if not workflow_action:
# and we diallow submit if different action is selected and different dialog embedded # and we diallow submit if different action is selected and different dialog embedded
request.form['workflow_action_rendered'] = workflow_action request.form['workflow_action_rendered'] = workflow_action
if is_updating or workflow_action_rendered != workflow_action: if kwargs.get("update_method", ""):
return context.Base_renderForm(dialog_id,
message=translate("Form updated."),
level="warning",
REQUEST=request)
if workflow_action_rendered != workflow_action:
# if we get all fields for the workflow form - do not bother user and proceed
try:
workflow_form_name = context.Base_getFormIdForWorkflowAction(form_id, '', workflow_action, uids=uids)
workflow_form = getattr(context, workflow_form_name) # this can throw if form is not defined yet
for group in workflow_form.get_groups():
if group.lower() == 'hidden':
continue
for field in workflow_form.get_fields_in_group(group):
if request.form.get("field_workflow_dialog_" + field.id, MARKER) is MARKER:
raise AttributeError("field_workflow_dialog_" + field.id) # direct access request.form["key"] does not throw because publisher eats the exception
except AttributeError:
return context.Base_renderForm(dialog_id, return context.Base_renderForm(dialog_id,
message=translate("Form updated."), message=translate("Form updated."),
level="warning", level="warning",
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>form_id, dialog_id, uids, workflow_action, workflow_action_rendered, comment=\'\', is_updating=False, **kwargs</string> </value> <value> <string>form_id, dialog_id, uids, workflow_action, workflow_action_rendered, comment=\'\', **kwargs</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
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