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
1
Issues
1
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
Roque
erp5
Commits
421b30e8
Commit
421b30e8
authored
Jul 03, 2019
by
Roque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_hal_json_style: refactoring on hateoas script
parent
f61caef1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
26 deletions
+11
-26
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+11
-26
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
421b30e8
...
@@ -1557,20 +1557,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -1557,20 +1557,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
response
.
setHeader
(
"Last-Modified"
,
DateTime
().
rfc822
())
response
.
setHeader
(
"Last-Modified"
,
DateTime
().
rfc822
())
REQUEST
.
set
(
"X-HATEOAS-CACHE"
,
1
)
REQUEST
.
set
(
"X-HATEOAS-CACHE"
,
1
)
fields_raw_properties
=
{}
# check if it's the first call to calculateHateoas so nothing was rendered yet
if
appcache
and
REQUEST
!=
None
and
response
!=
None
:
for
group
in
traversed_document
.
Form_getGroupTitleAndId
():
if
'hidden'
in
group
[
'gid'
]:
for
field
in
traversed_document
.
get_fields_in_group
(
group
[
'goid'
]):
if
field
.
id
==
"gadget_field_action_js_script"
:
fields_raw_properties
[
field
.
id
]
=
getFieldRawProperties
(
field
,
key_prefix
=
None
)
continue
for
field
in
traversed_document
.
get_fields_in_group
(
group
[
'goid'
]):
fields_raw_properties
[
field
.
id
]
=
getFieldRawProperties
(
field
,
key_prefix
=
None
)
if
fields_raw_properties
:
result_dict
[
'fields_raw_properties'
]
=
fields_raw_properties
elif
relative_url
==
'portal_workflow'
:
elif
relative_url
==
'portal_workflow'
:
result_dict
[
'_links'
][
'action_worklist'
]
=
{
result_dict
[
'_links'
][
'action_worklist'
]
=
{
"href"
:
url_template_dict
[
'worklist_template'
]
%
{
"href"
:
url_template_dict
[
'worklist_template'
]
%
{
...
@@ -2216,7 +2202,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -2216,7 +2202,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
elif (mode == '
appcache
'):
elif (mode == '
appcache
'):
##
##
# return raw form definition
# return raw form definition
and json structure
# render will be done in js side
# render will be done in js side
# Default properties shared by all ERP5 Document and Site
# Default properties shared by all ERP5 Document and Site
...
@@ -2270,7 +2256,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -2270,7 +2256,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
}
}
}
}
}
}
#
TODO: get from this method what is needed for appcaching, and avoid all rendering stuff
#
this gets needed form json structure: embedded; actions; links; my_form_definition field; form_id;
renderForm(traversed_document, view_instance, embedded_dict,
renderForm(traversed_document, view_instance, embedded_dict,
selection_params=extra_param_json, extra_param_json=extra_param_json, appcache=True)
selection_params=extra_param_json, extra_param_json=extra_param_json, appcache=True)
result_dict['
_embedded
'] = {
result_dict['
_embedded
'] = {
...
@@ -2284,7 +2270,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -2284,7 +2270,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
else:
else:
traversed_document_portal_type = traversed_document.getPortalType()
traversed_document_portal_type = traversed_document.getPortalType()
if traversed_document_portal_type in ("ERP5 Form", "ERP5 Report"):
if traversed_document_portal_type in ("ERP5 Form", "ERP5 Report"):
#
TODO: get from this method what is needed for appcaching, and avoid all rendering stuff
#
this gets the form fields (group_list)
renderFormDefinition(traversed_document, result_dict)
renderFormDefinition(traversed_document, result_dict)
if response is not None:
if response is not None:
response.setHeader("Cache-Control", "private, max-age=1800")
response.setHeader("Cache-Control", "private, max-age=1800")
...
@@ -2292,16 +2278,14 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -2292,16 +2278,14 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
response.setHeader("Last-Modified", DateTime().rfc822())
response.setHeader("Last-Modified", DateTime().rfc822())
REQUEST.set("X-HATEOAS-CACHE", 1)
REQUEST.set("X-HATEOAS-CACHE", 1)
fields_raw_properties = {}
fields_raw_properties = {}
# check if it'
s
the
first
call
to
calculateHateoas
so
nothing
was
rendered
yet
for group in traversed_document.Form_getGroupTitleAndId():
if
appcache
and
REQUEST
!=
None
and
response
!=
None
:
if '
hidden
' in group['
gid
']:
for
group
in
traversed_document
.
Form_getGroupTitleAndId
():
if
'hidden'
in
group
[
'gid'
]:
for
field
in
traversed_document
.
get_fields_in_group
(
group
[
'goid'
]):
if
field
.
id
==
"gadget_field_action_js_script"
:
fields_raw_properties
[
field
.
id
]
=
getFieldRawProperties
(
field
,
key_prefix
=
None
)
continue
for field in traversed_document.get_fields_in_group(group['
goid
']):
for field in traversed_document.get_fields_in_group(group['
goid
']):
fields_raw_properties
[
field
.
id
]
=
getFieldRawProperties
(
field
,
key_prefix
=
None
)
if field.id == "gadget_field_action_js_script":
fields_raw_properties[field.id] = getFieldRawProperties(field, key_prefix=None)
continue
for field in traversed_document.get_fields_in_group(group['
goid
']):
fields_raw_properties[field.id] = getFieldRawProperties(field, key_prefix=None)
if fields_raw_properties:
if fields_raw_properties:
result_dict['
fields_raw_properties
'] = fields_raw_properties
result_dict['
fields_raw_properties
'] = fields_raw_properties
...
@@ -2320,6 +2304,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -2320,6 +2304,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
default_form_definition["fields_raw_properties"] = result_dict["fields_raw_properties"].copy()
default_form_definition["fields_raw_properties"] = result_dict["fields_raw_properties"].copy()
result_dict.pop('
fields_raw_properties
', None)
result_dict.pop('
fields_raw_properties
', None)
result_dict["_embedded"]["_view"]["my_form_definition"]["default"] = default_form_definition
result_dict["_embedded"]["_view"]["my_form_definition"]["default"] = default_form_definition
return result_dict
return result_dict
mime_type = '
application
/
hal
+
json
'
mime_type = '
application
/
hal
+
json
'
...
...
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