Commit 45c03413 authored by Jérome Perrin's avatar Jérome Perrin

hal_json_style: prevent a translation of worklist with document count

When viewing the worklist page, a request is made to traverse portal_workflow,
which translate global worklist actions including the document count.

The non regression test was failing with:

    [u'Draft To Validate (1)'] != ['Draft To Validate']

and in real usage, several messages were added to Localizer.
parent f6d0f4c0
Pipeline #15471 failed with stage
......@@ -343,6 +343,14 @@ portal_absolute_url = portal.absolute_url()
preference_tool = portal.portal_preferences
Base_translateString = portal.Base_translateString
def translateWorklistActionName(worklist_action_name):
"""Translate a worklist action name, that may contain the document count.
Instead of translating "Draft to Validate (123)", we translate "Draft to Validate".
return Base_translateString(re.sub(r' \(\d+\)$', '', worklist_action_name))
preferred_html_style_developer_mode = preference_tool.getPreferredHtmlStyleDevelopperMode()
preferred_html_style_translator_mode = preference_tool.getPreferredHtmlStyleTranslatorMode()
......@@ -1519,7 +1527,10 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
'href': '%s' % view_action['url'],
'name': view_action['id'],
'icon': view_action['icon'],
'title': Base_translateString(view_action['title']),
'title': Base_translateString(
if 'worklist_id' in view_action
else view_action['title']),
global_action_type = ("view", "workflow", "object_new_content_action",
......@@ -2321,7 +2332,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
'href': url_template_dict["jio_search_template"] % {
"query": make_query({"query": query})
'name': Base_translateString(re.sub(r' \(\d+\)$', '', action['name'])),
'name': translateWorklistActionName(action['name']),
'count': action['count']
......@@ -16,6 +16,7 @@ import json
import re
import urllib
import mock
from zope.globalrequest import setRequest # pylint: disable=no-name-in-module, import-error
from Acquisition import aq_base
from Products.ERP5Form.Selection import Selection, DomainSelection
......@@ -2872,6 +2873,33 @@ return msg"
self.assertEqual(result_dict['_debug'], "worklist")
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return ""')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Base_translateString', 'msg, catalog="ui", encoding="utf8", lang="wo", **kw',
def test_getHateoasWorklist_portal_workflow_worklist_translation(self, document):
# Non regression test that traversing portal_workflow does not translate
# worklists with the actual count of document
fake_request = do_fake_request("GET")
default_gettext = self.portal.Localizer.erp5_ui.gettext
def gettext(message, **kw):
return default_gettext(message, **kw)
with mock.patch.object(self.portal.Localizer.erp5_ui.__class__, 'gettext', side_effect=gettext) as gettext_mock:
[x[1][0] for x in gettext_mock.mock_calls if x[1][0].startswith('Draft To Validate')],
['Draft To Validate'])
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return ""')
@simulate('Base_getRequestHeader', '*args, **kwargs',
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