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
Ekaterina
erp5
Commits
17e5aaf2
Commit
17e5aaf2
authored
Sep 07, 2017
by
Tomáš Peterka
Committed by
Tomáš Peterka
Sep 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[json_style] Cleanup ERP5Document_getHateoas.py to be more human friendly
parent
44dace24
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
66 deletions
+32
-66
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+32
-66
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
17e5aaf2
...
...
@@ -961,84 +961,52 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
elif
mode
==
'search'
:
#################################################
# Portal catalog search
#
# Possible call arguments example:
# form_relative_url: portal_skins/erp5_web/WebSite_view/listbox
# list_method: objectValues (Script providing listing)
# default_param_json: <base64 encoded JSON> (Additional search params)
# query: <str> (term for fulltext search)
# select_list: ['int_index', 'id', 'title', ...] (column names to select)
# limit: [15, 16] (begin_index, num_records)
# local_roles: TODO
#################################################
if
REQUEST
.
other
[
'method'
]
!=
"GET"
:
response
.
setStatus
(
405
)
return
""
# hardcoded responses for site and portal objects (which are not Documents!)
if
query
==
"__root__"
:
# XXX Hardcoded behaviour to get root object with jIO
sql_list
=
[
site_root
]
elif
query
==
"__portal__"
:
# XXX Hardcoded behaviour to get portal object with jIO
sql_list
=
[
portal
]
# document = site_root
# document_result = {
# # '_relative_url': site_root.getRelativeUrl(),
# '_links': {
# 'self': {
# "href": default_document_uri_template % {
# "root_url": site_root.absolute_url(),
# "relative_url": document.getRelativeUrl(),
# "script_id": script.id
# },
# },
# }
# }
# for select in select_list:
# document_result[select] = document.getProperty(select, d=None)
# result_dict['_embedded'] = {"contents": [document_result]}
else
:
# raise NotImplementedError("Unsupported query: %s" % query)
# # XXX
# length = len('/%s/' % portal.getId())
# # context.log(portal.portal_catalog(full_text=query, limit=limit, src__=1))
# context.log(query)
catalog_kw
=
{}
if
(
default_param_json
is
not
None
):
catalog_kw
=
byteify
(
json
.
loads
(
urlsafe_b64decode
(
default_param_json
)))
catalog_kw
=
{
"local_roles"
:
local_roles
,
"limit"
:
limit
,
"sort_on"
:
()
# default is empty tuple
}
if
default_param_json
is
not
None
:
catalog_kw
.
update
(
byteify
(
json
.
loads
(
urlsafe_b64decode
(
default_param_json
))))
if
query
:
catalog_kw
[
"full_text"
]
=
query
if
sort_on
is
not
None
:
if
isinstance
(
sort_on
,
list
):
catalog_kw
[
'sort_on'
]
=
tuple
((
byteify
(
sort_col
),
byteify
(
sort_order
))
for
sort_col
,
sort_order
in
map
(
json
.
loads
,
sort_on
))
else
:
sort_col
,
sort_order
=
json
.
loads
(
sort_on
)
catalog_kw
[
'sort_on'
]
=
((
byteify
(
sort_col
),
byteify
(
sort_order
)),
)
if
(
list_method
is
None
):
callable_list_method
=
portal
.
portal_catalog
else
:
callable_list_method
=
getattr
(
traversed_document
,
list_method
)
tmp_sort_on
=
()
if
sort_on
is
not
None
:
if
isinstance
(
sort_on
,
list
):
for
grain
in
sort_on
:
tmp_sort_on
+=
(
tuple
([
x
for
x
in
byteify
(
json
.
loads
(
grain
))]),)
else
:
#only one single criteria
tmp_sort_on
=
(
tuple
([
x
for
x
in
byteify
(
json
.
loads
(
sort_on
))]),)
sql_list
=
callable_list_method
(
**
catalog_kw
)
if
query
:
sql_list
=
callable_list_method
(
full_text
=
query
,
limit
=
limit
,
sort_on
=
tmp_sort_on
,
local_roles
=
local_roles
,
**
catalog_kw
)
else
:
sql_list
=
callable_list_method
(
limit
=
limit
,
sort_on
=
tmp_sort_on
,
local_roles
=
local_roles
,
**
catalog_kw
)
result_list
=
[]
# returned "content" of the search
result_list
=
[]
# if (select_list is None):
# # Only include links
# for sql_document in sql_list:
# document = sql_document.getObject()
# result_list.append({
# "href": default_document_uri_template % {
# "root_url": site_root.absolute_url(),
# "relative_url": document.getRelativeUrl(),
# "script_id": script.id
# },
# })
# result_dict['_links']['contents'] = result_list
#
# else:
# Cast to list if only one element is provided
editable_field_dict
=
{}
if
select_list
is
None
:
...
...
@@ -1066,7 +1034,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
document
=
sql_document
document_uid
=
sql_document
.
uid
document_result
=
{
# '_relative_url': sql_document.path[length:],
'_links'
:
{
'self'
:
{
"href"
:
default_document_uri_template
%
{
...
...
@@ -1092,10 +1059,9 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
else
:
tmp_value
=
getProtectedProperty
(
document
,
select
)
property_value
=
renderField
(
traversed_document
,
editable_field_dict
[
select
],
form
,
tmp_value
,
key
=
'field_%s_%s'
%
(
editable_field_dict
[
select
].
id
,
document_uid
))
property_value
=
renderField
(
traversed_document
,
editable_field_dict
[
select
],
form
,
tmp_value
,
key
=
'field_%s_%s'
%
(
editable_field_dict
[
select
].
id
,
document_uid
))
REQUEST
.
other
.
pop
(
'cell'
,
None
)
else
:
property_value
=
getProtectedProperty
(
document
,
select
)
...
...
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