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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tomáš Peterka
erp5
Commits
a26aa2dd
Commit
a26aa2dd
authored
Nov 28, 2017
by
Tomáš Peterka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
7b8798f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
9 deletions
+39
-9
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+39
-9
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
a26aa2dd
...
...
@@ -9,10 +9,12 @@ In general it always returns a JSON reponse in HATEOAS format specification.
:param relative_url: an URL of `traversed_document` to operate on (it must have an object_view)
Only in mode == 'search'
:param query:
:param select_list:
:param limit:
tr
:param query:
string-serialized Query
:param select_list:
list of strings to select from search result object
:param limit:
tuple(start_index, num_records) which is further passed to list_method BUT not every list_method takes it into account
:param form_relative_url: {str} relative URL of a form FIELD issuing the search (listbox/relation field...)
it can be None in case of special listboxes like List of Modules
or relative path like "portal_skins/erp5_ui_test/FooModule_viewFooList/listbox"
Only in mode == 'form'
:param form:
...
...
@@ -1421,15 +1423,18 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
elif
same_type
(
select_list
,
""
):
select_list
=
[
select_list
]
# form field issuing this search
source_field
=
portal
.
restrictedTraverse
(
form_relative_url
)
if
form_relative_url
else
None
# extract form field definition into `editable_field_dict`
editable_field_dict
=
{}
listbox_form
=
None
listbox_field_id
=
None
if
form_relative_url
is
not
None
:
listbox_field
=
portal
.
restrictedTraverse
(
form_relative_url
)
listbox_field_id
=
listbox
_field
.
id
if
source_field
is
not
None
and
source_field
.
meta_type
==
"ListBox"
:
listbox_field_id
=
source
_field
.
id
# XXX Proxy field are not correctly handled in traversed_document of web site
listbox_form
=
getattr
(
traversed_document
,
listbox
_field
.
aq_parent
.
id
)
listbox_form
=
getattr
(
traversed_document
,
source
_field
.
aq_parent
.
id
)
for
select
in
select_list
:
# See Listbox.py getValueList --> getEditableField & getColumnAliasList method
# In short: there are Form Field definitions which names start with
...
...
@@ -1464,9 +1469,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# this dict will hold all resolved values
contents_item
=
{
# _links.self.href is mandatory for JIO so it can create reference to the
# (listbox) item alone
'_links'
:
{
# _links.self.href is mandatory for JIO so it can create reference to items alone
'self'
:
{
"href"
:
default_document_uri_template
%
{
"root_url"
:
site_root
.
absolute_url
(),
...
...
@@ -1524,6 +1528,32 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
}
})
# Compute statistics if the search issuer was ListBox
# or in future if the stats (SUM) are required by JIO call
contents_stat_list
=
[]
if
source_field
is
not
None
and
source_field
.
meta_type
==
"ListBox"
:
# in case the search was issued by listbox we can provide results of
# stat_method and count_method back to the caller
# XXX: we should check whether they asked for it
stat_method
=
source_field
.
get_value
(
'stat_method'
)
stat_columns
=
source_field
.
get_value
(
'stat_columns'
)
contents_stat
=
{}
if
len
(
stat_columns
)
>
0
:
# prefer stat per columns as it is in ListBox
# always called on current context
for
stat_name
,
stat_script
in
stat_columns
:
contents_stat
[
stat_name
]
=
getattr
(
traversed_document
,
stat_script
)(
**
catalog_kw
)
contents_stat_list
.
append
(
contents_stat
)
elif
stat_method
!=
""
and
stat_method
.
getMethodName
()
!=
list_method_name
:
# global stat_method is second - should return dictionary or list of dictionaries
# where all "fields" should be accessible by its "select" name
contents_stat_list
=
getattr
(
traversed_document
,
stat_method
.
getMethodName
())(
**
catalog_kw
)
if
len
(
contents_stat_list
)
>
0
:
result_dict
[
'_embedded'
].
update
({
'contents'
:
contents_list
})
# We should cleanup the selection if it exists in catalog params BUT
# we cannot because it requires escalated Permission.'modifyPortal' so
# the correct solution would be to ReportSection.popReport but unfortunately
...
...
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