Commit ac5836bb authored by Tatuya Kamada's avatar Tatuya Kamada

erp5_hal_json_style: Fix double translation on parent title when traversing a child document

Before this fix, double translation on Sale Order title was happened every time
displaying a Sale Order Line, for example.
parent fd5a9d60
...@@ -1428,13 +1428,18 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1428,13 +1428,18 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
container = traversed_document.getParentValue() container = traversed_document.getParentValue()
if container != portal: if container != portal:
# Jio does not support fetching the root document for now # Jio does not support fetching the root document for now
if container.getRelativeUrl():
container_name = ensureUTF8(container.getTranslatedTitle())
else:
# for example in portal_skin
container_name = ensureUTF8(container.getTitle())
result_dict['_links']['parent'] = { result_dict['_links']['parent'] = {
"href": default_document_uri_template % { "href": default_document_uri_template % {
"root_url": site_root.absolute_url(), "root_url": site_root.absolute_url(),
"relative_url": container.getRelativeUrl(), "relative_url": container.getRelativeUrl(),
"script_id": script.id "script_id": script.id
}, },
"name": Base_translateString(container.getTitle()), "name": container_name
} }
# Find current action URL and extract embedded view # Find current action URL and extract embedded view
......
...@@ -2973,6 +2973,32 @@ return msg" ...@@ -2973,6 +2973,32 @@ return msg"
result_dict = json.loads(result) result_dict = json.loads(result)
self.assertEqual(result_dict['title'], 'Foo_zhongwen') self.assertEqual(result_dict['title'], 'Foo_zhongwen')
@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_not_adding_parent_title_translation(self, document):
document_title = document.getTitle() + "_not_translate_parent_message_catalog"
document.setTitle(document_title)
message_catalog = self.portal.Localizer.erp5_ui
self.assertFalse(message_catalog.message_exists(document_title))
foo_line = document.newContent(portal_type='Foo Line')
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request, mode="traverse",
relative_url=foo_line.getRelativeUrl(), view="view")
result_dict = json.loads(result)
# The document title includes 'ö' at the last in this test class, so calling decode("UTF-8")
self.assertEqual(result_dict['_links']['parent'],
{"href": "urn:jio:get:%s" % document.getRelativeUrl(), "name": document.getTitle().decode("UTF-8")})
# make sure traversing the child document does not adding the parent title translation
self.assertFalse(message_catalog.message_exists(document_title))
class TestERP5Action_getHateoas(ERP5HALJSONStyleSkinsMixin): class TestERP5Action_getHateoas(ERP5HALJSONStyleSkinsMixin):
......
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