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
623fdf1e
Commit
623fdf1e
authored
Mar 04, 2019
by
Roque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
discussion tool: removing hardcoded form definition in hateoas script
parent
9e6c6ba7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
5 deletions
+30
-5
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+30
-5
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
623fdf1e
...
@@ -392,6 +392,7 @@ def getFieldDefault(form, field, key, value=None):
...
@@ -392,6 +392,7 @@ def getFieldDefault(form, field, key, value=None):
def
renderField
(
traversed_document
,
field
,
form
,
value
=
MARKER
,
meta_type
=
None
,
key
=
None
,
key_prefix
=
None
,
selection_params
=
None
,
request_field
=
True
):
def
renderField
(
traversed_document
,
field
,
form
,
value
=
MARKER
,
meta_type
=
None
,
key
=
None
,
key_prefix
=
None
,
selection_params
=
None
,
request_field
=
True
):
"""Extract important field's attributes into `result` dictionary."""
"""Extract important field's attributes into `result` dictionary."""
log
(
"[DEBUG] rendering field %s for traversed_document %s and form %s "
%
(
field
.
id
,
traversed_document
,
form
))
if
selection_params
is
None
:
if
selection_params
is
None
:
selection_params
=
{}
selection_params
=
{}
...
@@ -422,6 +423,9 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None, k
...
@@ -422,6 +423,9 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None, k
"description"
:
field
.
get_value
(
"description"
),
"description"
:
field
.
get_value
(
"description"
),
}
}
if
field
.
get_value
(
"extra"
):
result
[
"renderjs_extra"
]
=
field
.
get_value
(
"extra"
)
if
"Field"
in
meta_type
:
if
"Field"
in
meta_type
:
# fields have default value and can be required (unlike boxes)
# fields have default value and can be required (unlike boxes)
result
[
"required"
]
=
field
.
get_value
(
"required"
)
if
field
.
has_value
(
"required"
)
else
None
result
[
"required"
]
=
field
.
get_value
(
"required"
)
if
field
.
has_value
(
"required"
)
else
None
...
@@ -885,6 +889,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
...
@@ -885,6 +889,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
'name'
:
form
.
id
'name'
:
form
.
id
}
}
log
(
"[DEBUG] calling calculateHateoas of form_definition"
)
response_dict
[
'_embedded'
]
=
{
response_dict
[
'_embedded'
]
=
{
'form_definition'
:
calculateHateoas
(
'form_definition'
:
calculateHateoas
(
traversed_document
=
form
,
traversed_document
=
form
,
...
@@ -897,7 +902,6 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
...
@@ -897,7 +902,6 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
form_definition
=
True
form_definition
=
True
)
)
}
}
use_relation_form_page_template
=
(
form
.
pt
==
"relation_form"
)
use_relation_form_page_template
=
(
form
.
pt
==
"relation_form"
)
if
use_relation_form_page_template
:
if
use_relation_form_page_template
:
# Provide the list of possible listboxes
# Provide the list of possible listboxes
...
@@ -955,6 +959,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
...
@@ -955,6 +959,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
if
not
field
.
get_value
(
"enabled"
):
if
not
field
.
get_value
(
"enabled"
):
continue
continue
try
:
try
:
log
(
"[DEBUG] calling renderField"
)
response_dict
[
field
.
id
]
=
renderField
(
traversed_document
,
field
,
form
,
key_prefix
=
key_prefix
,
selection_params
=
selection_params
,
request_field
=
not
use_relation_form_page_template
)
response_dict
[
field
.
id
]
=
renderField
(
traversed_document
,
field
,
form
,
key_prefix
=
key_prefix
,
selection_params
=
selection_params
,
request_field
=
not
use_relation_form_page_template
)
if
field_errors
.
has_key
(
field
.
id
):
if
field_errors
.
has_key
(
field
.
id
):
response_dict
[
field
.
id
][
"error_text"
]
=
field_errors
[
field
.
id
].
error_text
response_dict
[
field
.
id
][
"error_text"
]
=
field_errors
[
field
.
id
].
error_text
...
@@ -1136,7 +1141,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -1136,7 +1141,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
query
=
None
,
select_list
=
None
,
limit
=
None
,
form
=
None
,
query
=
None
,
select_list
=
None
,
limit
=
None
,
form
=
None
,
relative_url
=
None
,
restricted
=
None
,
list_method
=
None
,
relative_url
=
None
,
restricted
=
None
,
list_method
=
None
,
default_param_json
=
None
,
form_relative_url
=
None
,
extra_param_json
=
None
,
form_definition
=
False
):
default_param_json
=
None
,
form_relative_url
=
None
,
extra_param_json
=
None
,
form_definition
=
False
):
if
relative_url
:
if
relative_url
:
try
:
try
:
traversed_document
=
site_root
.
restrictedTraverse
(
str
(
relative_url
))
traversed_document
=
site_root
.
restrictedTraverse
(
str
(
relative_url
))
...
@@ -1192,7 +1196,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -1192,7 +1196,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
'status'
:
statusLevelToString
(
portal_status_level
)
'status'
:
statusLevelToString
(
portal_status_level
)
}
}
if
(
restricted
==
1
)
and
(
portal
.
portal_membership
.
isAnonymousUser
()):
if
(
restricted
==
1
)
and
(
portal
.
portal_membership
.
isAnonymousUser
()):
#if False:
#if False:
#when appcache tries to call this script it fails due unauthorized if not logged in
#when appcache tries to call this script it fails due unauthorized if not logged in
...
@@ -1329,8 +1332,10 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -1329,8 +1332,10 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# REQUEST but expect all (formerly) URL query parameters to appear in their **kw
# REQUEST but expect all (formerly) URL query parameters to appear in their **kw
# thus we send extra_param_json (=rjs way of passing parameters to REQUEST) as
# thus we send extra_param_json (=rjs way of passing parameters to REQUEST) as
# selection_params so they get into callable's **kw.
# selection_params so they get into callable's **kw.
log
(
"[DEBUG] CALLING RENDERFORM from calculatehateoas. with form %s"
%
view_instance
.
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
)
selection_params
=
extra_param_json
,
extra_param_json
=
extra_param_json
)
log
(
"[DEBUG] returned from renderForm call in calculatehateoas"
)
result_dict
[
'_embedded'
]
=
{
result_dict
[
'_embedded'
]
=
{
'_view'
:
embedded_dict
'_view'
:
embedded_dict
...
@@ -1477,11 +1482,25 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -1477,11 +1482,25 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
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"
):
renderFormDefinition
(
traversed_document
,
result_dict
)
renderFormDefinition
(
traversed_document
,
result_dict
)
log
(
result_dict
[
"group_list"
])
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"
)
response
.
setHeader
(
"Vary"
,
"Cookie,Authorization,Accept-Encoding"
)
response
.
setHeader
(
"Vary"
,
"Cookie,Authorization,Accept-Encoding"
)
response
.
setHeader
(
"Last-Modified"
,
DateTime
().
rfc822
())
response
.
setHeader
(
"Last-Modified"
,
DateTime
().
rfc822
())
REQUEST
.
set
(
"X-HATEOAS-CACHE"
,
1
)
REQUEST
.
set
(
"X-HATEOAS-CACHE"
,
1
)
field_info_dict
=
{}
# check if it's the first call to calculateHateoas so traversed_document is rendered as form
if
REQUEST
!=
None
and
response
!=
None
:
for
group
in
traversed_document
.
Form_getGroupTitleAndId
():
if
'hidden'
in
group
[
'gid'
]:
continue
for
field
in
traversed_document
.
get_fields_in_group
(
group
[
'goid'
]):
my_field
=
renderField
(
traversed_document
,
field
,
traversed_document
,
key_prefix
=
None
,
selection_params
=
{},
request_field
=
True
)
field_info_dict
[
field
.
id
]
=
my_field
if
field_info_dict
:
result_dict
[
'field_info_dict'
]
=
field_info_dict
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'
]
%
{
...
@@ -2087,9 +2106,15 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -2087,9 +2106,15 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
result_dict["_embedded"]["_view"]["my_form_definition"]["default"] = result_dict["_embedded"]["_view"]["_embedded"]["form_definition"].copy()
result_dict["_embedded"]["_view"]["my_form_definition"]["default"] = result_dict["_embedded"]["_view"]["_embedded"]["form_definition"].copy()
result_dict["_embedded"]["_view"]["my_form_definition"]["default"]["group_list"] = result_dict["group_list"]
result_dict["_embedded"]["_view"]["my_form_definition"]["default"]["group_list"] = result_dict["group_list"]
result_dict["_embedded"]["_view"]["my_form_definition"]["default"]["_actions"] = result_dict["_embedded"]["_view"]["_actions"]
result_dict["_embedded"]["_view"]["my_form_definition"]["default"]["_actions"] = result_dict["_embedded"]["_view"]["_actions"]
log('
result_dict
[
"field_info_dict"
]
')
log(result_dict["field_info_dict"])
result_dict["_embedded"]["_view"]["my_form_definition"]["default"]["field_info_dict"] = result_dict["field_info_dict"].copy()
result_dict.pop('
field_info_dict
', None)
#'''
# [HARDCODED] the form definition must contain a field_info_dict with all the rendered fields
# [HARDCODED] the form definition must contain a field_info_dict with all the rendered fields
# for now is hardcoded only for "HTML Post"
# for now is hardcoded only for "HTML Post"
# TODO:
achieve this iterating the group_list fields and calling renderField
# TODO:
CHECK differences with result_dict["field_info_dict"] like key is "field_my_title" instead of "title" and specially my_text_content
if result_dict["title"] == "HTML Post":
if result_dict["title"] == "HTML Post":
result_dict["_embedded"]["_view"]["my_form_definition"]["default"]["field_info_dict"] = {
result_dict["_embedded"]["_view"]["my_form_definition"]["default"]["field_info_dict"] = {
"my_title": {
"my_title": {
...
@@ -2144,7 +2169,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
...
@@ -2144,7 +2169,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
"key": "form_id",
"key": "form_id",
"type": "StringField"
"type": "StringField"
}
}
}
}
#'''
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