Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastien Robin
erp5
Commits
34ee4bdc
Commit
34ee4bdc
authored
Oct 26, 2021
by
Tatuya Kamada
Browse files
Options
Browse Files
Download
Plain Diff
erp5_hal_json_style: Fix double translation in ERP5Document_getHateoas
See merge request
!1498
parents
fd5a9d60
42f67e1c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
12 deletions
+108
-12
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+19
-12
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
...plateItem/portal_components/test.erp5.testHalJsonStyle.py
+89
-0
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
34ee4bdc
...
...
@@ -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
,
...
...
@@ -1428,13 +1430,18 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
container
=
traversed_document
.
getParentValue
()
if
container
!=
portal
:
# 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'
]
=
{
"href"
:
default_document_uri_template
%
{
"root_url"
:
site_root
.
absolute_url
(),
"relative_url"
:
container
.
getRelativeUrl
(),
"script_id"
:
script
.
id
},
"name"
:
Base_translateString
(
container
.
getTitle
()),
"name"
:
container_name
}
# Find current action URL and extract embedded view
...
...
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
View file @
34ee4bdc
...
...
@@ -2973,6 +2973,95 @@ return msg"
result_dict
=
json
.
loads
(
result
)
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
))
@
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
\
n
title|Title
\
n
quantity|Quantity
\
n
start_date|Date
\
n
catalog.uid|Uid'
,
field_editable_columns
=
'id|ID
\
n
title|Title
\
n
quantity|quantity
\
n
start_date|Date'
,
# modify these two for test
field_search_columns
=
'id|ID
\
n
title|Title_test_nested_message_catalog
\
n
quantity|Quantity
\
n
start_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
\
n
title|Title
\
n
quantity|Quantity
\
n
start_date|Date
\
n
catalog.uid|Uid'
,
field_editable_columns
=
'id|ID
\
n
title|Title
\
n
quantity|quantity
\
n
start_date|Date'
,
field_search_columns
=
'id|ID
\
n
title|Title
\
n
quantity|Quantity
\
n
start_date|Date'
,
)
class
TestERP5Action_getHateoas
(
ERP5HALJSONStyleSkinsMixin
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment