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
170a5bd9
Commit
170a5bd9
authored
Jun 26, 2019
by
Roque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_hal_json_style: new mode "appcache" for hateoas script
parent
13ef1cb0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
1 deletion
+96
-1
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+96
-1
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
170a5bd9
...
...
@@ -67,7 +67,8 @@ from collections import OrderedDict
MARKER
=
[]
COUNT_LIMIT
=
1000
appcache
=
True
if
context
.
REQUEST
.
get
(
'appcache'
,
None
)
is
not
None
else
False
# TODO replace appcache var use by (mode = 'appcache')
appcache
=
True
if
mode
==
"appcache"
else
False
if
REQUEST
is
None
:
recursive_call
=
True
...
...
@@ -2220,6 +2221,100 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
result_dict["worklist"] = work_list
elif (mode == '
appcache
'):
##
# return raw form definition
# render will be done in js side
# Default properties shared by all ERP5 Document and Site
current_action = {}
result_dict['
title
'] = traversed_document.getTitle()
extra_param_json = {}
# TODO: '
type
' should be include outside "_links", but itrequires changes on js side rendering
if not is_portal:
document_type_name = traversed_document.getPortalType()
document_type = getattr(portal.portal_types, document_type_name, None)
if document_type is not None:
result_dict['
_links
']['
type
'] = {
"href": default_document_uri_template % {
"root_url": site_root.absolute_url(),
"relative_url": document_type.getRelativeUrl(),
"script_id": script.id
},
"name": Base_translateString(traversed_document.getPortalType())
}
# TODO: '
parent
' should be include outside "_links", but it requires changes on js side rendering
if not is_portal:
container = traversed_document.getParentValue()
if container != portal:
result_dict['
_links
']['
parent
'] = {
"href": default_document_uri_template % {
"root_url": site_root.absolute_url(),
"relative_url": container.getRelativeUrl(),
"script_id": script.id
},
"name": Base_translateString(container.getTitle()),
}
# Find current action URL and extract embedded view
erp5_action_dict = portal.Base_filterDuplicateActions(
portal.portal_actions.listFilteredActionsFor(traversed_document))
for erp5_action_key in erp5_action_dict.keys():
for view_action in erp5_action_dict[erp5_action_key]:
if (view == view_action['
id
']):
current_action = parseActionUrl('
%
s
' % view_action['
url
'])
if view and (view != '
view
') and (current_action.get('
view_id
', None) is None):
current_action['
view_id
'] = view
current_action['
url
'] = '
%
s
/%
s
' % (traversed_document.getRelativeUrl(), view)
current_action['
params
'] = {}
if current_action.get('
view_id
', ''):
view_instance = getattr(traversed_document, current_action['
view_id
'])
if (view_instance is not None):
embedded_dict = {
'
_links
': {
'
self
': {
'
href
': current_action['
url
']
}
}
}
# TODO: get from this method what is needed for appcaching, and avoid all rendering stuff
renderForm(traversed_document, view_instance, embedded_dict,
selection_params=extra_param_json, extra_param_json=extra_param_json)
result_dict['
_embedded
'] = {
'
_view
': embedded_dict
}
if is_site_root:
result_dict['
default_view
'] = '
view
'
REQUEST.set("X-HATEOAS-CACHE", 1)
else:
traversed_document_portal_type = traversed_document.getPortalType()
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
renderFormDefinition(traversed_document, result_dict)
if response is not None:
response.setHeader("Cache-Control", "private, max-age=1800")
response.setHeader("Vary", "Cookie,Authorization,Accept-Encoding")
response.setHeader("Last-Modified", DateTime().rfc822())
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
else
:
raise
NotImplementedError
(
"Unsupported mode %s"
%
mode
)
...
...
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