Commit b121ba2c authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Cédric Le Ninivin

erp5_api_style: EXPERIMENTAL API works with HTTP GET method

parent 30604c3c
......@@ -94,8 +94,12 @@ class jIOWebSection(WebSection):
return default
@convertTojIOAPICall
def _asjIOStyle(self, mode, text_content):
return self.ERP5Site_asjIOStyle(mode=mode, text_content=text_content)
def _asjIOStyle(self, mode, text_content="", data_dict=None):
return self.ERP5Site_asjIOStyle(
mode=mode,
text_content=text_content,
data_dict=data_dict,
)
security.declareProtected(Permissions.View, 'get')
def get(self): #pylint:disable=arguments-differ
......@@ -104,6 +108,8 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
"""
# Register current web site physical path for later URL generation
if self.REQUEST.REQUEST_METHOD == "GET":
return self._asjIOStyle(mode="get", text_content=self.REQUEST.form.keys()[0])
return self._asjIOStyle(mode="get", text_content=self.REQUEST.get('BODY'))
security.declareProtected(Permissions.View, 'post')
......@@ -131,4 +137,6 @@ class jIOWebSection(WebSection):
__bobo_traverse__ from DocumentExtensibleTraversableMixin is not called
"""
# Register current web site physical path for later URL generation
if self.REQUEST.REQUEST_METHOD == "GET":
return self._asjIOStyle(mode="allDocs", text_content=self.REQUEST.form.keys()[0])
return self._asjIOStyle(mode="allDocs", text_content=self.REQUEST.get('BODY'))
......@@ -63,12 +63,15 @@ if mode not in mode_dict:
return "Used Mode is not defined in the mode list %s" % mode_dict.keys()
# Check JSON Form
try:
data = json_loads_byteified(text_content)
except BaseException as e:
return logError(str(e), error_name="API-JSON-INVALID-JSON")
if not isinstance(data, dict):
return logError("Did not received a JSON Object", error_name="API-JSON-NOT-JSON-OBJECT")
if not data_dict:
try:
data = json_loads_byteified(text_content)
except BaseException as e:
return logError(str(e), error_name="API-JSON-INVALID-JSON")
if not isinstance(data, dict):
return logError("Did not received a JSON Object", error_name="API-JSON-NOT-JSON-OBJECT")
else:
data = data_dict
# If get or put, valid Id is expected
if mode in ("get", "put"):
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>mode="", text_content="", document_id="", *arg, **kw</string> </value>
<value> <string>mode="", text_content="", data_dict=None, document_id="", *arg, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
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