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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matevz Golob
erp5
Commits
b4f0c21b
Commit
b4f0c21b
authored
Feb 28, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_hal_json_style] Render domain tree for each listbox
parent
37fa9e68
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
2 deletions
+57
-2
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+52
-1
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
...plateItem/portal_components/test.erp5.testHalJsonStyle.py
+5
-1
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
b4f0c21b
...
...
@@ -148,6 +148,54 @@ def ensureDeserialized(obj):
return
datetime
.
time
(
*
tuple
(
map
(
int
,
match_obj
.
groups
())))
return
obj
NBSP_UTF8
=
u'
\
xA0
'
.
encode
(
'utf-8'
)
def
generateDomainTreeList
(
url_tool
,
domain_tool
,
domain
,
depth
,
domain_list
):
if
depth
:
domain_list
.
append
((
'%s%s'
%
(
NBSP_UTF8
*
4
*
(
depth
-
1
),
domain
.
getTitle
()),
'/'
.
join
(
url_tool
.
getRelativeContentPath
(
domain
)[
2
:])
))
new_depth
=
depth
+
1
for
sub_domain
in
domain_tool
.
getChildDomainValueList
(
domain
,
depth
=
depth
):
generateDomainTreeList
(
url_tool
,
domain_tool
,
sub_domain
,
new_depth
,
domain_list
)
def
getDomainSelection
(
domain_list
):
root_dict
=
{}
if
len
(
domain_list
)
>
0
:
category_tool
=
portal
.
portal_categories
domain_tool
=
portal
.
portal_domains
preference_tool
=
portal
.
portal_preferences
url_tool
=
portal
.
portal_url
for
base_domain_id
in
domain_list
:
domain
=
None
if
category_tool
is
not
None
:
domain
=
category_tool
.
restrictedTraverse
(
base_domain_id
,
None
)
if
domain
is
not
None
:
root_dict
[
base_domain_id
]
=
getattr
(
domain
,
preference_tool
.
getPreference
(
'preferred_category_child_item_list_method_id'
,
'getCategoryChildCompactLogicalPathItemList'
)
)(
local_sort_id
=
(
'int_index'
,
'translated_title'
),
checked_permission
=
'View'
,
filter_node
=
0
,
display_none_category
=
0
)
elif
domain_tool
is
not
None
:
try
:
domain
=
domain_tool
.
getDomainByPath
(
base_domain_id
,
None
)
except
KeyError
:
domain
=
None
if
domain
is
not
None
:
# XXX Implement recursive fetch
domain_list
=
[]
generateDomainTreeList
(
url_tool
,
domain_tool
,
domain
,
0
,
domain_list
)
root_dict
[
base_domain_id
]
=
domain_list
return
root_dict
def
getProtectedProperty
(
document
,
select
):
"""getProtectedProperty is a security-aware substitution for builtin `getattr`
...
...
@@ -803,8 +851,11 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
"query"
:
make_query
({
"query"
:
sql_catalog
.
buildQuery
(
list_method_query_dict
,
ignore_unknown_columns
=
True
).
asSearchTextExpression
(
sql_catalog
)})}
ignore_unknown_columns
=
True
).
asSearchTextExpression
(
sql_catalog
)})},
"domain_root_list"
:
field
.
get_value
(
"domain_root_list"
)
})
result
[
"domain_dict"
]
=
getDomainSelection
([
x
[
0
]
for
x
in
result
[
"domain_root_list"
]])
if
(
list_method_custom
is
not
None
):
result
[
"list_method_template"
]
=
list_method_custom
return
result
...
...
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
View file @
b4f0c21b
...
...
@@ -536,7 +536,8 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
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'
,)
field_search_columns
=
'id|ID
\
n
title|Title
\
n
quantity|Quantity
\
n
start_date|Date'
,
field_domain_root_list
=
'foo_category|FooCat
\
n
foo_domain|FooDomain
\
n
not_existing_domain|NotExisting'
,)
parent
=
document
.
getParentValue
()
fake_request
=
do_fake_request
(
"GET"
)
...
...
@@ -630,6 +631,9 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'listbox'
][
'sort_column_list'
],
[[
'id'
,
'ID'
],
[
'title'
,
'Title'
],
[
'quantity'
,
'Quantity'
],
[
'start_date'
,
'Date'
]])
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'listbox'
][
'list_method_template'
],
'%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search&relative_url=foo_module%%2F%s&form_relative_url=portal_skins/erp5_ui_test/Foo_view/listbox&list_method=objectValues&default_param_json=eyJwb3J0YWxfdHlwZSI6IFsiRm9vIExpbmUiXSwgImlnbm9yZV91bmtub3duX2NvbHVtbnMiOiB0cnVlfQ=={&query,select_list*,limit*,sort_on*,local_roles*,selection_domain*}'
%
(
self
.
portal
.
absolute_url
(),
document
.
getId
()))
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'listbox'
][
'domain_root_list'
],
[[
'foo_category'
,
'FooCat'
],
[
'foo_domain'
,
'FooDomain'
],
[
'not_existing_domain'
,
'NotExisting'
]])
NBSP_prefix
=
u'
\
xA0
'
*
4
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'listbox'
][
'domain_dict'
],
{
'foo_domain'
:
[[
'a'
,
'a'
],
[
'%sa1'
%
NBSP_prefix
,
'a/a1'
],
[
'%sa2'
%
NBSP_prefix
,
'a/a2'
],
[
'b'
,
'b'
]],
'foo_category'
:
[[
'a'
,
'a'
],
[
'a/a1'
,
'a/a1'
],
[
'a/a2'
,
'a/a2'
],
[
'b'
,
'b'
]]})
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'_links'
][
'traversed_document'
][
'href'
],
'urn:jio:get:%s'
%
document
.
getRelativeUrl
())
self
.
assertEqual
(
result_dict
[
'_embedded'
][
'_view'
][
'_links'
][
'traversed_document'
][
'name'
],
document
.
getRelativeUrl
())
...
...
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