Commit 42f67e1c authored by Tatuya Kamada's avatar Tatuya Kamada

erp5_hal_json_style: Fix double translation on listbox column titles when traversing a document

Double translation happened when:

- For sql_catalog.isValidColumn(name)
- When search_columns is empty
- When selection_sort_order and sort_columns are empty

So delaying translation on column titles until *_column_list are finalised.
parent ac5836bb
......@@ -695,26 +695,25 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None,
the original REQUEST with sent POST values from the parent form. We can save those
values into our query method and reconstruct them meanwhile calling asynchronous jio.allDocs.
"""
_translate = Base_translateString
# column definition in ListBox own value 'columns' is superseded by dynamic
# column definition from Selection for specific Report ListBoxes; the same for editable_columns
column_list = [(name, _translate(title)) for name, title in (selection_params.get('selection_columns', [])
column_list = [(name, title) for name, title in (selection_params.get('selection_columns', [])
or field.get_value("columns"))]
editable_column_list = [(name, _translate(title)) for name, title in (selection_params.get('editable_columns', [])
editable_column_list = [(name, title) for name, title in (selection_params.get('editable_columns', [])
or field.get_value("editable_columns"))]
all_column_list = [(name, _translate(title)) for name, title in field.get_value("all_columns")]
all_column_list = [(name, title) for name, title in field.get_value("all_columns")]
catalog_column_list = [(name, title)
for name, title in OrderedDict(column_list + all_column_list).items()
if sql_catalog.isValidColumn(name)]
# try to get specified searchable columns and fail back to all searchable columns
search_column_list = [(name, _translate(title))
search_column_list = [(name, title)
for name, title in (field.get_value("search_columns") or catalog_column_list)
if sql_catalog.isValidColumn(name)]
# try to get specified sortable columns and fail back to searchable fields
sort_column_list = [(name, _translate(title))
sort_column_list = [(name, title)
for name, title in (selection_params.get('selection_sort_order', [])
or field.get_value("sort_columns") or search_column_list)
if sql_catalog.isValidColumn(name)]
......@@ -824,13 +823,16 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None,
# line["_relative_url"] = document.getRelativeUrl()
# line_list.append(line)
def translateColumnListTitle(column_list):
return [(name, Base_translateString(title)) for (name, title) in column_list]
result.update({
"column_list": column_list,
"all_column_list": all_column_list,
"search_column_list": search_column_list,
"column_list": translateColumnListTitle(column_list),
"all_column_list": translateColumnListTitle(all_column_list),
"search_column_list": translateColumnListTitle(search_column_list),
"sort" :field.get_value('sort'),
"sort_column_list": sort_column_list,
"editable_column_list": editable_column_list,
"sort_column_list": translateColumnListTitle(sort_column_list),
"editable_column_list": translateColumnListTitle(editable_column_list),
"show_anchor": field.get_value("anchor"),
"show_select": field.get_value("select"),
"portal_type": portal_type_list,
......
......@@ -3000,6 +3000,69 @@ return msg"
# make sure traversing the child document does not adding the parent title translation
self.assertFalse(message_catalog.message_exists(document_title))
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Base_translateString', 'msg, catalog="ui", encoding="utf8", lang="wo", **kw',
code_string)
@createIndexedDocument()
@changeSkin('Hal')
def test_getHateoasForm_listbox_nested_message_catalog(self, document):
document.Foo_view.listbox.ListBox_setPropertyList(
field_title = 'Foo Lines',
field_list_method = 'objectValues',
field_portal_types = 'Foo Line | Foo Line',
field_stat_method = 'portal_catalog',
field_stat_columns = 'quantity | Foo_statQuantity',
field_editable = 1,
field_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date\ncatalog.uid|Uid',
field_editable_columns = 'id|ID\ntitle|Title\nquantity|quantity\nstart_date|Date',
# modify these two for test
field_search_columns = 'id|ID\ntitle|Title_test_nested_message_catalog\nquantity|Quantity\nstart_date|Date',
# if sort_columns is empty search_columns are used for the fallback
field_sort_columns = '',
)
self.portal.Base_addUITestTranslation(message='Title_test_nested_message_catalog',
translation='biaoti_test_nested_message_catalog', language='wo')
message_catalog = self.portal.Localizer.erp5_ui
# Check the 'wo' message is not in the 'en' message_catalog before running the test
self.assertFalse(message_catalog.message_exists('biaoti_test_nested_message_catalog'))
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request, mode="traverse",
relative_url=document.getRelativeUrl(), view="view")
result_dict = json.loads(result)
self.assertEqual(result_dict['_embedded']['_view']['listbox']['column_list'],
[['id', 'ID'], ['title', 'biaoti'], ['quantity', 'Quantity'], ['start_date', 'Date'], ['catalog.uid', 'Uid']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['editable_column_list'],
[['id', 'ID'], ['title', 'biaoti'], ['quantity', 'quantity'], ['start_date', 'Date']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['search_column_list'],
[['id', 'ID'], ['title', 'biaoti_test_nested_message_catalog'], ['quantity', 'Quantity'], ['start_date', 'Date']])
# If sort_column is empty, search_column_list is used as the fall-back
self.assertEqual(result_dict['_embedded']['_view']['listbox']['sort_column_list'],
[['id', 'ID'], ['title', 'biaoti_test_nested_message_catalog'], ['quantity', 'Quantity'], ['start_date', 'Date']])
# check traversing listbox does not adding the 'wo' message as a 'en' message
self.assertFalse(message_catalog.message_exists('biaoti_test_nested_message_catalog'))
# reset to default
document.Foo_view.listbox.ListBox_setPropertyList(
field_title = 'Foo Lines',
field_list_method = 'objectValues',
field_portal_types = 'Foo Line | Foo Line',
field_stat_method = 'portal_catalog',
field_stat_columns = 'quantity | Foo_statQuantity',
field_editable = 1,
field_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date\ncatalog.uid|Uid',
field_editable_columns = 'id|ID\ntitle|Title\nquantity|quantity\nstart_date|Date',
field_search_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date',
)
class TestERP5Action_getHateoas(ERP5HALJSONStyleSkinsMixin):
@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