Commit 7642f7db authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Titouan Soulard

erp5_api_style: EXPERIMENTAL API works with HTTP GET method

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