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
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,
...
@@ -961,84 +961,52 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
elif
mode
==
'search'
:
elif
mode
==
'search'
:
#################################################
#################################################
# Portal catalog 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"
:
if
REQUEST
.
other
[
'method'
]
!=
"GET"
:
response
.
setStatus
(
405
)
response
.
setStatus
(
405
)
return
""
return
""
# hardcoded responses for site and portal objects (which are not Documents!)
if
query
==
"__root__"
:
if
query
==
"__root__"
:
# XXX Hardcoded behaviour to get root object with jIO
sql_list
=
[
site_root
]
sql_list
=
[
site_root
]
elif
query
==
"__portal__"
:
elif
query
==
"__portal__"
:
# XXX Hardcoded behaviour to get portal object with jIO
sql_list
=
[
portal
]
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
:
else
:
# raise NotImplementedError("Unsupported query: %s" % query)
catalog_kw
=
{
"local_roles"
:
local_roles
,
"limit"
:
limit
,
# # XXX
"sort_on"
:
()
# default is empty tuple
# length = len('/%s/' % portal.getId())
}
# # context.log(portal.portal_catalog(full_text=query, limit=limit, src__=1))
if
default_param_json
is
not
None
:
# context.log(query)
catalog_kw
.
update
(
byteify
(
json
.
loads
(
urlsafe_b64decode
(
default_param_json
))))
catalog_kw
=
{}
if
query
:
if
(
default_param_json
is
not
None
):
catalog_kw
[
"full_text"
]
=
query
catalog_kw
=
byteify
(
json
.
loads
(
urlsafe_b64decode
(
default_param_json
)))
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
):
if
(
list_method
is
None
):
callable_list_method
=
portal
.
portal_catalog
callable_list_method
=
portal
.
portal_catalog
else
:
else
:
callable_list_method
=
getattr
(
traversed_document
,
list_method
)
callable_list_method
=
getattr
(
traversed_document
,
list_method
)
tmp_sort_on
=
()
sql_list
=
callable_list_method
(
**
catalog_kw
)
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
))]),)
if
query
:
result_list
=
[]
# returned "content" of the search
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
=
[]
# 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
# Cast to list if only one element is provided
editable_field_dict
=
{}
editable_field_dict
=
{}
if
select_list
is
None
:
if
select_list
is
None
:
...
@@ -1066,7 +1034,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -1066,7 +1034,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
document
=
sql_document
document
=
sql_document
document_uid
=
sql_document
.
uid
document_uid
=
sql_document
.
uid
document_result
=
{
document_result
=
{
# '_relative_url': sql_document.path[length:],
'_links'
:
{
'_links'
:
{
'self'
:
{
'self'
:
{
"href"
:
default_document_uri_template
%
{
"href"
:
default_document_uri_template
%
{
...
@@ -1092,10 +1059,9 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -1092,10 +1059,9 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
else
:
else
:
tmp_value
=
getProtectedProperty
(
document
,
select
)
tmp_value
=
getProtectedProperty
(
document
,
select
)
property_value
=
renderField
(
traversed_document
,
editable_field_dict
[
select
],
form
,
property_value
=
renderField
(
tmp_value
,
traversed_document
,
editable_field_dict
[
select
],
form
,
tmp_value
,
key
=
'field_%s_%s'
%
(
editable_field_dict
[
select
].
id
,
key
=
'field_%s_%s'
%
(
editable_field_dict
[
select
].
id
,
document_uid
))
document_uid
))
REQUEST
.
other
.
pop
(
'cell'
,
None
)
REQUEST
.
other
.
pop
(
'cell'
,
None
)
else
:
else
:
property_value
=
getProtectedProperty
(
document
,
select
)
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