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
Titouan Soulard
erp5
Commits
052b33da
Commit
052b33da
authored
Nov 19, 2024
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_json_form: support argument mappings
parent
c03e06fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletion
+24
-1
bt5/erp5_json_form/ModuleComponentTemplateItem/portal_components/document.erp5.JSONForm.py
...tTemplateItem/portal_components/document.erp5.JSONForm.py
+24
-1
No files found.
bt5/erp5_json_form/ModuleComponentTemplateItem/portal_components/document.erp5.JSONForm.py
View file @
052b33da
...
...
@@ -69,10 +69,33 @@ class JSONForm(JSONType, TextDocument):
raise
jsonschema
.
exceptions
.
ValidationError
(
validation_result
.
message
)
else
:
raise
ValueError
(
json
.
dumps
(
validation_result
))
data_dict
=
json
.
loads
(
json_data
)
if
self
.
getAfterMethodId
():
return
getattr
(
getattr
(
self
,
"aq_parent"
,
None
),
self
.
getAfterMethodId
())(
json_data
,
self
)
after_method
=
getattr
(
getattr
(
self
,
"aq_parent"
,
None
),
self
.
getAfterMethodId
())
mapped_data_dict
=
self
.
_mapArguments
(
data_dict
,
"input"
)
# XXX: argument name is wrong
mapped_data_dict
[
"form_reference"
]
=
self
output_dict
=
after_method
(
**
mapped_data_dict
)
if
not
isinstance
(
output_dict
,
dict
):
output_dict
=
{}
mapped_output_dict
=
self
.
_mapArguments
(
output_dict
,
"output"
)
return
json
.
dumps
(
mapped_output_dict
)
return
"Nothing to do"
def
_mapArguments
(
self
,
arguments
,
mapping_type
):
mappings
=
{
x
.
getSource
():
x
.
getDestination
()
for
x
in
self
.
objectValues
(
portal_type
=
"Argument Mapping"
)
if
x
.
getMappingType
()
==
mapping_type
}
mapped_arguments
=
{}
for
(
k
,
v
)
in
arguments
.
iteritems
():
if
k
in
mappings
:
mapped_arguments
[
mappings
[
k
]]
=
v
else
:
mapped_arguments
[
k
]
=
v
return
mapped_arguments
def
validateJSON
(
self
,
json_data
,
list_error
=
False
):
"""
Validate contained JSON with the Schema defined in the Portal Type.
...
...
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