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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
erp5
Commits
2f41d248
Commit
2f41d248
authored
Apr 20, 2018
by
Tomáš Peterka
Committed by
Tomáš Peterka
Apr 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[hal_json_style] Add and document `extra_param_json` usage
parent
4c273cae
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
29 deletions
+96
-29
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_callDialogMethod.py
...portal_skins/erp5_hal_json_style/Base_callDialogMethod.py
+23
-12
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_callDialogMethod.xml
...ortal_skins/erp5_hal_json_style/Base_callDialogMethod.xml
+1
-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
+67
-12
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
...plateItem/portal_components/test.erp5.testHalJsonStyle.py
+5
-4
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_callDialogMethod.py
View file @
2f41d248
"""
Generic method called when submitting a form in dialog mode.
Responsible for validating form data and redirecting to the form action.
Please note that the new UI has deprecated use of Selections. Your scripts
will no longer receive `selection_name` nor `selection` in their arguments.
There are runtime values hidden in every form (injected by getHateoas Script):
form_id - previous form ID (backward compatibility reasons)
dialog_id - current form dialog ID
dialog_method - method to be called - can be either update_method or dialog_method of the Dialog Form
"""
from
Products.ERP5Type.Log
import
log
,
DEBUG
,
INFO
,
WARNING
from
Products.ERP5Type.Log
import
log
,
DEBUG
,
INFO
,
WARNING
,
ERROR
from
Products.Formulator.Errors
import
FormValidationError
,
ValidationError
from
ZTUtils
import
make_query
import
json
# XXX We should not use meta_type properly,
# XXX We need to discuss this problem.(yusei)
def
isFieldType
(
field
,
type_name
):
if
field
.
meta_type
==
'ProxyField'
:
field
=
field
.
getRecursiveTemplateField
()
return
field
.
meta_type
==
type_name
from
Products.Formulator.Errors
import
FormValidationError
,
ValidationError
from
ZTUtils
import
make_query
# Kato: I do not understand why we throw away REQUEST from parameters (hidden in **kw)
# and use container.REQUEST just to introduce yet another global state. Maybe because
# container.REQUEST is used in other places.
...
...
@@ -27,30 +32,31 @@ request = kw.get('REQUEST', None) or container.REQUEST
request_form
=
request
.
form
error_message
=
''
translate
=
context
.
Base_translateString
portal
=
context
.
getPortalObject
()
# Make this script work alike no matter if called by a script or a request
kw
.
update
(
request_form
)
# Exceptions for UI
if
dialog_method
==
'Base_configureUI'
:
return
context
.
Base_configureUI
(
form_id
=
kw
[
'form_id'
]
,
return
context
.
Base_configureUI
(
form_id
=
form_id
,
selection_name
=
kw
[
'selection_name'
],
field_columns
=
kw
[
'field_columns'
],
stat_columns
=
kw
[
'stat_columns'
])
# Exceptions for Sort
if
dialog_method
==
'Base_configureSortOn'
:
return
context
.
Base_configureSortOn
(
form_id
=
kw
[
'form_id'
]
,
return
context
.
Base_configureSortOn
(
form_id
=
form_id
,
selection_name
=
kw
[
'selection_name'
],
field_sort_on
=
kw
[
'field_sort_on'
],
field_sort_order
=
kw
[
'field_sort_order'
])
# Exceptions for Workflow
if
dialog_method
==
'Workflow_statusModify'
:
return
context
.
Workflow_statusModify
(
form_id
=
kw
[
'form_id'
]
,
return
context
.
Workflow_statusModify
(
form_id
=
form_id
,
dialog_id
=
dialog_id
)
# Exception for edit relation
if
dialog_method
==
'Base_editRelation'
:
return
context
.
Base_editRelation
(
form_id
=
kw
[
'form_id'
]
,
return
context
.
Base_editRelation
(
form_id
=
form_id
,
field_id
=
kw
[
'field_id'
],
selection_name
=
kw
[
'list_selection_name'
],
selection_index
=
kw
[
'selection_index'
],
...
...
@@ -60,7 +66,7 @@ if dialog_method == 'Base_editRelation':
# Exception for create relation
# Not used in new UI - relation field implemented using JIO calls from JS
if
dialog_method
==
'Base_createRelation'
:
return
context
.
Base_createRelation
(
form_id
=
kw
[
'form_id'
]
,
return
context
.
Base_createRelation
(
form_id
=
form_id
,
selection_name
=
kw
[
'list_selection_name'
],
selection_index
=
kw
[
'selection_index'
],
base_category
=
kw
[
'base_category'
],
...
...
@@ -77,6 +83,7 @@ if dialog_method == 'Folder_delete':
md5_object_uid_list
=
kw
[
'md5_object_uid_list'
])
form
=
getattr
(
context
,
dialog_id
)
extra_param
=
json
.
loads
(
extra_param_json
or
"{}"
)
# form can be a python script that returns the form
if
not
hasattr
(
form
,
'validate_all_to_request'
):
...
...
@@ -188,6 +195,10 @@ if listbox_uid is not None and kw.has_key('list_selection_name'):
# Remove empty values for make_query.
clean_kw
=
dict
((
k
,
v
)
for
k
,
v
in
kw
.
items
()
if
v
not
in
(
None
,
[],
()))
# Add rest of extra param into arguments of the target method
kw
.
update
(
extra_param
)
# Finally we will call the Dialog Method
# Handle deferred style, unless we are executing the update action
if
dialog_method
!=
update_method
and
clean_kw
.
get
(
'deferred_style'
,
0
):
clean_kw
[
'deferred_portal_skin'
]
=
clean_kw
.
get
(
'portal_skin'
,
None
)
...
...
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_callDialogMethod.xml
View file @
2f41d248
...
...
@@ -50,7 +50,7 @@
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
dialog_method, dialog_id,
dialog_category=\'\', update_method=None
, **kw
</string>
</value>
<value>
<string>
dialog_method, dialog_id,
form_id, dialog_category=\'\', update_method=None, extra_param_json="{}"
, **kw
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
...
...
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
2f41d248
This diff is collapsed.
Click to expand it.
bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py
View file @
2f41d248
...
...
@@ -567,7 +567,7 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self
.
assertEqual
(
result_dict
[
'_links'
][
'action_object_view'
][
0
][
'name'
],
"view"
)
self
.
assertEqual
(
result_dict
[
'_links'
][
'action_workflow'
][
0
][
'href'
],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=custom_action_no_dialog&
form_id=Foo_view
"
%
(
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=custom_action_no_dialog&
extra_param_json=eyJmb3JtX2lkIjogIkZvb192aWV3In0=
"
%
(
self
.
portal
.
absolute_url
(),
urllib
.
quote_plus
(
document
.
getRelativeUrl
())))
self
.
assertEqual
(
result_dict
[
'_links'
][
'action_workflow'
][
0
][
'title'
],
"Custom Action No Dialog"
)
...
...
@@ -586,7 +586,7 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self
.
assertEqual
(
result_dict
[
'_links'
][
'site_root'
][
'name'
],
self
.
portal
.
web_site_module
.
hateoas
.
getTitle
())
self
.
assertEqual
(
result_dict
[
'_links'
][
'action_object_new_content_action'
][
'href'
],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=create_a_document&
form_id=Foo_view
"
%
(
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=create_a_document&
extra_param_json=eyJmb3JtX2lkIjogIkZvb192aWV3In0=
"
%
(
self
.
portal
.
absolute_url
(),
urllib
.
quote_plus
(
document
.
getRelativeUrl
())))
self
.
assertEqual
(
result_dict
[
'_links'
][
'action_object_new_content_action'
][
'title'
],
"Create a Document"
)
...
...
@@ -1721,7 +1721,7 @@ class TestERP5Document_getHateoas_mode_bulk(ERP5HALJSONStyleSkinsMixin):
self
.
assertEqual
(
result_dict
[
'result_list'
][
0
][
'_links'
][
'action_object_view'
][
0
][
'name'
],
"view"
)
self
.
assertEqual
(
result_dict
[
'result_list'
][
0
][
'_links'
][
'action_workflow'
][
0
][
'href'
],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=custom_action_no_dialog&
form_id=Foo_view
"
%
(
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=custom_action_no_dialog&
extra_param_json=eyJmb3JtX2lkIjogIkZvb192aWV3In0=
"
%
(
self
.
portal
.
absolute_url
(),
urllib
.
quote_plus
(
document
.
getRelativeUrl
())))
self
.
assertEqual
(
result_dict
[
'result_list'
][
0
][
'_links'
][
'action_workflow'
][
0
][
'title'
],
"Custom Action No Dialog"
)
...
...
@@ -1734,7 +1734,7 @@ class TestERP5Document_getHateoas_mode_bulk(ERP5HALJSONStyleSkinsMixin):
self
.
assertEqual
(
result_dict
[
'result_list'
][
0
][
'_links'
][
'site_root'
][
'name'
],
self
.
portal
.
web_site_module
.
hateoas
.
getTitle
())
self
.
assertEqual
(
result_dict
[
'result_list'
][
0
][
'_links'
][
'action_object_new_content_action'
][
'href'
],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=create_a_document&
form_id=Foo_view
"
%
(
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=%s&view=create_a_document&
extra_param_json=eyJmb3JtX2lkIjogIkZvb192aWV3In0=
"
%
(
self
.
portal
.
absolute_url
(),
urllib
.
quote_plus
(
document
.
getRelativeUrl
())))
self
.
assertEqual
(
result_dict
[
'result_list'
][
0
][
'_links'
][
'action_object_new_content_action'
][
'title'
],
"Create a Document"
)
...
...
@@ -1965,6 +1965,7 @@ class TestERP5Action_getHateoas(ERP5HALJSONStyleSkinsMixin):
REQUEST
=
fake_request
,
dialog_method
=
'Foo_doNothing'
,
# 'Workflow_statusModify' would lead us by a different path in the code
dialog_id
=
'Foo_viewCustomWorkflowRequiredActionDialog'
,
form_id
=
'Foo_view'
)
self
.
assertEqual
(
fake_request
.
RESPONSE
.
status
,
400
)
...
...
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