Commit 1fecf1e3 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[hal_json] Limit temporarily mass actions to 50 documents

because of Mass Workflow transition which is not optimised yet
parent ac14df70
......@@ -17,6 +17,8 @@ from Products.Formulator.Errors import FormValidationError, ValidationError
from ZTUtils import make_query
import json
DOCUMENT_COUNT_LIMIT = 50
# http://stackoverflow.com/a/13105359
def byteify(value):
if isinstance(value, dict):
......@@ -206,13 +208,14 @@ kw.update(**extra_param)
kw.update(keep_items=extra_param) # better backward compatibility
# early-stop if user selected all or too many documents
if len(extra_param.get("uids", ())) >= 1000 or extra_param.get("query", MARKER) == "":
if len(extra_param.get("uids", ())) >= DOCUMENT_COUNT_LIMIT or extra_param.get("query", MARKER) == "":
if dialog_method == update_method:
pass # do not interrupt on UPDATE
elif extra_param.get("basedialog_force_submit", 0) == 0:
extra_param["basedialog_force_submit"] = 1
if len(extra_param.get("uids", ())) >= 1000:
translated_message=translate("Too many documents selected! Submit again to proceed with the first 1000 or Cancel and narrow down your search.")
if len(extra_param.get("uids", ())) >= DOCUMENT_COUNT_LIMIT:
translated_message=translate("Too many documents selected! Submit again to proceed with the first ${limit} or Cancel and narrow down your search.",
mapping={'limit': DOCUMENT_COUNT_LIMIT})
else:
translated_message=translate("All documents are selected! Submit again to proceed or Cancel and narrow down your search.")
return context.Base_renderForm(
......@@ -221,7 +224,7 @@ if len(extra_param.get("uids", ())) >= 1000 or extra_param.get("query", MARKER)
level=WARNING,
keep_items=extra_param,
form_data=form_data)
elif len(extra_param.get("uids", ())) >= 1000:
elif len(extra_param.get("uids", ())) >= DOCUMENT_COUNT_LIMIT:
# remove UIDS from the extra_param to force re-computation because the
# query will be the same but UIDS should change
del extra_param['uids']
......
......@@ -67,6 +67,7 @@ from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
from collections import OrderedDict
MARKER = []
DOCUMENT_COUNT_LIMIT = 50
if REQUEST is None:
REQUEST = context.REQUEST
......@@ -1108,7 +1109,8 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
method_args = selectKwargsForCallable(getattr(traversed_document, form.action), {}, {'uids': None})
if "uids" in method_args:
extra_param_json["uids"] = [int(getattr(document, "uid"))
for document in traversed_document.Base_searchUsingListbox(last_listbox, query or extra_param_json.get("query", None), limit=1000)]
for document in traversed_document.Base_searchUsingListbox(
last_listbox, query or extra_param_json.get("query", None), limit=DOCUMENT_COUNT_LIMIT)]
if query is not None:
extra_param_json["query"] = query
else:
......@@ -1716,7 +1718,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# a UID == None is a bit hack-ish way of signaling that the list_method
# needs list of UID instead of a regular query
catalog_kw["uid"] = [int(getattr(document, "uid"))
for document in traversed_document.Base_searchUsingListbox(context.Base_getListbox(extra_param_json["form_id"]), query, limit=1000, **catalog_kw)]
for document in traversed_document.Base_searchUsingListbox(
context.Base_getListbox(extra_param_json["form_id"]), query, limit=DOCUMENT_COUNT_LIMIT, **catalog_kw)]
elif query:
catalog_kw["full_text"] = query
......
......@@ -24,15 +24,15 @@
<tr><th colspan="3">Create Foo objects with distinguishible titles (Title 1%, Title 2%)</th></tr>
<tr><td>open</td>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=1000&amp;num:int=400</td><td></td></tr>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=1000&amp;num:int=40</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Created Successfully.</td><td></td></tr>
<tr><td>open</td>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=2000&amp;num:int=400</td><td></td></tr>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=2000&amp;num:int=40</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Created Successfully.</td><td></td></tr>
<tr><td>open</td>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=3000&amp;num:int=400</td><td></td></tr>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=3000&amp;num:int=40</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Created Successfully.</td><td></td></tr>
......@@ -55,7 +55,7 @@
<tr><td>click</td>
<td>//ul[@data-role="listview"]//a[@data-i18n="Change State"]</td><td></td></tr>
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 1200)', 'footer': 'Records 1 - 3 / 1200'}">
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 120)', 'footer': 'Records 1 - 3 / 120'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
......@@ -66,7 +66,7 @@
<td>value=validate_action</td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block tal:define="notification_configuration python: {'class': 'error', 'text': 'Too many documents selected! Submit again to proceed with the first 1000 or Cancel and narrow down your search.'}">
<tal:block tal:define="notification_configuration python: {'class': 'error', 'text': 'Too many documents selected! Submit again to proceed with the first 50 or Cancel and narrow down your search.'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_notification" />
</tal:block>
......@@ -90,7 +90,7 @@
</tal:block>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_filter" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 200)', 'footer': 'Records 1 - 3 / 200'}">
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 70)', 'footer': 'Records 1 - 3 / 70'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
......
......@@ -23,11 +23,11 @@
<td>renderjs_url</td></tr>
<tr><td>open</td>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=1000&amp;num:int=600</td><td></td></tr>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=1000&amp;num:int=40</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Created Successfully.</td><td></td></tr>
<tr><td>open</td>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=2000&amp;num:int=600</td><td></td></tr>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=2000&amp;num:int=40</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Created Successfully.</td><td></td></tr>
......@@ -45,7 +45,7 @@
<tr><td>click</td>
<td>//ul[@data-role="listview"]//a[@data-i18n="Empty Mass Action"]</td><td></td></tr>
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 1200)', 'footer': 'Records 1 - 3 / 1200'}">
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 80)', 'footer': 'Records 1 - 3 / 80'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
......@@ -55,18 +55,18 @@
<tr><td>click</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_field_listbox.html')]//table/thead/tr/th//a[@data-i18n="ID"]</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 1200)', 'footer': 'Records 1 - 3 / 1200'}">
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 80)', 'footer': 'Records 1 - 3 / 80'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
<tr><td>waitForText</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_field_listbox.html')]//table/tbody/tr[1]/td[1]//p</td>
<td>2599</td></tr>
<td>2039</td></tr>
<tr><td>waitForText</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_field_listbox.html')]//table/tbody/tr[2]/td[1]//p</td>
<td>2598</td></tr>
<td>2038</td></tr>
<tr><td>waitForText</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_field_listbox.html')]//table/tbody/tr[3]/td[1]//p</td>
<td>2597</td></tr>
<td>2037</td></tr>
<tr><td>type</td>
......@@ -78,18 +78,18 @@
<tr><td>click</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_field_listbox.html')]//nav/a[@data-i18n="Next"]</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block tal:define="pagination_configuration python: {'header': '(4 - 6 / 1200)', 'footer': 'Records 4 - 6 / 1200'}">
<tal:block tal:define="pagination_configuration python: {'header': '(4 - 6 / 80)', 'footer': 'Records 4 - 6 / 80'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
<tr><td>waitForText</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_field_listbox.html')]//table/tbody/tr[1]/td[1]//p</td>
<td>2596</td></tr>
<td>2036</td></tr>
<tr><td>waitForText</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_field_listbox.html')]//table/tbody/tr[2]/td[1]//p</td>
<td>2595</td></tr>
<td>2035</td></tr>
<tr><td>waitForText</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_field_listbox.html')]//table/tbody/tr[3]/td[1]//p</td>
<td>2594</td></tr>
<td>2034</td></tr>
<tr><th rowspan="1" colspan="3">Updating the dialog must not trigger warning about all selected</th></tr>
......@@ -102,7 +102,7 @@
<tr><th rowspan="1" colspan="3">Submitting, however, must warn the user</th></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block tal:define="notification_configuration python: {'class': 'error', 'text': 'Too many documents selected! Submit again to proceed with the first 1000 or Cancel and narrow down your search.'}">
<tal:block tal:define="notification_configuration python: {'class': 'error', 'text': 'Too many documents selected! Submit again to proceed with the first 50 or Cancel and narrow down your search.'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_notification" />
</tal:block>
......@@ -152,7 +152,7 @@
<tr><th rowspan="1" colspan="3">Warn the user and compute form_hash in the background</th></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block tal:define="notification_configuration python: {'class': 'error', 'text': 'Too many documents selected! Submit again to proceed with the first 1000 or Cancel and narrow down your search.'}">
<tal:block tal:define="notification_configuration python: {'class': 'error', 'text': 'Too many documents selected! Submit again to proceed with the first 50 or Cancel and narrow down your search.'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_notification" />
</tal:block>
......@@ -186,7 +186,7 @@
<tal:block tal:define='search_query string:( title: "Title 1%" )'>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/search_in_form_list" />
</tal:block>
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 600)', 'footer': 'Records 1 - 3 / 600'}">
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 40)', 'footer': 'Records 1 - 3 / 40'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
......@@ -200,7 +200,7 @@
<td>//ul[@data-role="listview"]//a[@data-i18n="Empty Mass Action"]</td><td></td></tr>
<tr><th colspan="3">Make sure that search stays</th></tr>
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 600)', 'footer': 'Records 1 - 3 / 600'}">
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 40)', 'footer': 'Records 1 - 3 / 40'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
......@@ -210,7 +210,7 @@
<tr><td>click</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_field_listbox.html')]//nav/a[@data-i18n="Next"]</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block tal:define="pagination_configuration python: {'header': '(4 - 6 / 600)', 'footer': 'Records 4 - 6 / 600'}">
<tal:block tal:define="pagination_configuration python: {'header': '(4 - 6 / 40)', 'footer': 'Records 4 - 6 / 40'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
......@@ -234,7 +234,7 @@
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/triggle_filter" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/change_filter_to_or" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_filter" />
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 1200)', 'footer': 'Records 1 - 3 / 1200'}">
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 80)', 'footer': 'Records 1 - 3 / 80'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
......@@ -247,13 +247,13 @@
<tr><td>click</td>
<td>//ul[@data-role="listview"]//a[@data-i18n="Empty Mass Action"]</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 1200)', 'footer': 'Records 1 - 3 / 1200'}">
<tal:block tal:define="pagination_configuration python: {'header': '(1 - 3 / 80)', 'footer': 'Records 1 - 3 / 80'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block tal:define="notification_configuration python: {'class': 'error', 'text': 'Too many documents selected! Submit again to proceed with the first 1000 or Cancel and narrow down your search.'}">
<tal:block tal:define="notification_configuration python: {'class': 'error', 'text': 'Too many documents selected! Submit again to proceed with the first 50 or Cancel and narrow down your search.'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_notification" />
</tal:block>
......
......@@ -33,7 +33,7 @@ if add_empty:
transition_dict = {}
for result in context.Base_searchUsingFormIdAndQuery(form_id, query, limit=1000):
for result in context.Base_searchUsingFormIdAndQuery(form_id, query, limit=50):
for action in action_tool.listFilteredActionsFor(result.getObject()).get('workflow', []):
transition_dict[action['id']] = action['title']
......
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