Commit 052b33da authored by Titouan Soulard's avatar Titouan Soulard

erp5_json_form: support argument mappings

parent c03e06fb
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment