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
Yusei Tahara
erp5
Commits
b57989f3
Commit
b57989f3
authored
Dec 29, 2017
by
Tomáš Peterka
Committed by
Tomáš Peterka
Jan 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[hal_json] Reinforce getHateoas
- failure in callable does not throw error - recursive tales support
parent
b072a620
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
+8
-3
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+8
-3
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
b57989f3
...
@@ -132,7 +132,7 @@ def getUidAndAccessorForAnything(search_result, result_index, traversed_document
...
@@ -132,7 +132,7 @@ def getUidAndAccessorForAnything(search_result, result_index, traversed_document
value = getter(random_object, "value")
value = getter(random_object, "value")
"""
"""
if
hasattr
(
search_result
,
"getObject"
):
if
hasattr
(
search_result
,
"getObject"
):
#
search_result = search_result.getObject()
#
"Brain" object - which simulates DB Cursor thus result must have UID
contents_uid
=
search_result
.
uid
contents_uid
=
search_result
.
uid
# every document indexed in catalog has to have relativeUrl
# every document indexed in catalog has to have relativeUrl
contents_relative_url
=
getRealRelativeUrl
(
search_result
)
contents_relative_url
=
getRealRelativeUrl
(
search_result
)
...
@@ -257,7 +257,8 @@ def getAttrFromAnything(search_result, select, search_property_getter, search_pr
...
@@ -257,7 +257,8 @@ def getAttrFromAnything(search_result, select, search_property_getter, search_pr
contents_value
=
contents_value
()
contents_value
=
contents_value
()
except
(
AttributeError
,
KeyError
,
Unauthorized
)
as
error
:
except
(
AttributeError
,
KeyError
,
Unauthorized
)
as
error
:
log
(
"Could not evaluate {} on {} with error {!s}"
.
format
(
log
(
"Could not evaluate {} on {} with error {!s}"
.
format
(
contents_value
,
search_result
,
error
),
level
=
100
)
# WARNING
contents_value
,
search_result
,
error
),
level
=
200
)
# ERROR
contents_value
=
None
# make resulting value JSON serializable
# make resulting value JSON serializable
if
contents_value
is
not
None
:
if
contents_value
is
not
None
:
...
@@ -1446,13 +1447,17 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -1446,13 +1447,17 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
}
}
for
select
in
select_list
:
for
select
in
select_list
:
default_field_value
=
None
# every `select` can have a template field or be just a exotic getter for a value
if
editable_field_dict
.
has_key
(
select
):
if
editable_field_dict
.
has_key
(
select
):
# cell has a Form Field template thus render it using the field
# cell has a Form Field template thus render it using the field
# fields are nice because they are standard
# fields are nice because they are standard
REQUEST
.
set
(
'cell'
,
search_result
)
REQUEST
.
set
(
'cell'
,
search_result
)
# if default value is given by evaluating Tales expression then we only
# if default value is given by evaluating Tales expression then we only
# put "cell" to request (expected by tales) and let the field evaluate
# put "cell" to request (expected by tales) and let the field evaluate
if
getattr
(
editable_field_dict
[
select
].
tales
,
"default"
,
""
)
==
""
:
if
(
not
editable_field_dict
[
select
].
get_tales
(
"default"
)
and
# no tales
(
not
hasattr
(
editable_field_dict
[
select
],
"get_recursive_tales"
)
or
# no recursive tales
editable_field_dict
[
select
].
get_recursive_tales
(
"default"
)
==
""
)):
# if there is no tales expr (or is empty) we extract the value from search result
# if there is no tales expr (or is empty) we extract the value from search result
default_field_value
=
getAttrFromAnything
(
search_result
,
select
,
property_getter
,
property_hasser
,
{})
default_field_value
=
getAttrFromAnything
(
search_result
,
select
,
property_getter
,
property_hasser
,
{})
...
...
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