Commit c9cc425e authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

erp5_jio: more hardcoded code to handle task reports + code to handle query

parent 770c5009
......@@ -51,24 +51,28 @@
<item>
<key> <string>_body</string> </key>
<value> <string>import json\n
from Products.ERP5Type.Log import log\n
#from Products.ERP5Type.Log import log\n
# use JSON.parse as json.loads and JSON.stringify as json.dumps\n
\n
context.REQUEST.response.setHeader("Access-Control-Allow-Origin", "*")\n
\n
try: option = json.loads(context.REQUEST.form["option"])\n
jio = context.JIO_class()\n
\n
try: option = jio.jsonUtf8Loads(context.REQUEST.form["option"])\n
except KeyError:\n
option = {}\n
try:\n
mode = str(context.REQUEST.form["mode"])\n
except KeyError:\n
mode = "normal"\n
\n
jio = context.JIO_class(mode=mode)\n
try: mode = str(context.REQUEST.form["mode"])\n
except KeyError: mode = "generic"\n
jio.setMode(mode)\n
\n
metadata_json = jio.getAllDocuments(option)\n
\n
return jio.sendSuccess(metadata_json)\n
\n
document_list = context.portal_catalog(portal_type="Web Page")\n
# document_list = context.portal_catalog(portal_type="Web Page")\n
\n
return jio.sendSuccess(jio.getAllDocsFromDocumentList(document_list, include_docs=option.get("include_docs")))\n
# return jio.sendSuccess(jio.getAllDocsFromDocumentList(document_list, include_docs=option.get("include_docs")))\n
</string> </value>
</item>
<item>
......
......@@ -75,7 +75,7 @@ jio.setMode(mode)\n
try:\n
metadata_json = jio.getDocumentMetadata(doc)\n
except ValueError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot get document", str(e)))\n
return jio.sendError(jio.createConflictDict("Cannot get document", str(e)))\n
except LookupError as e:\n
return jio.sendError(jio.createNotFoundDict("Cannot get document", str(e)))\n
\n
......
......@@ -75,7 +75,7 @@ jio.setMode(mode)\n
try:\n
attachment_data = jio.getDocumentAttachment(doc)\n
except ValueError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot get attachment", str(e)))\n
return jio.sendError(jio.createConflictDict("Cannot get attachment", str(e)))\n
except LookupError as e:\n
return jio.sendError(jio.createNotFoundDict("Cannot get attachment", str(e)))\n
\n
......
......@@ -60,7 +60,8 @@ jio = context.JIO_class()\n
\n
try: doc = jio.jsonUtf8Loads(context.REQUEST.form["doc"])\n
except KeyError:\n
return jio.sendError(jio.createBadRequestDict("Cannot get document", "No document information received"))\n
return jio.sendError(jio.createBadRequestDict(\n
"Cannot get document", "No document information received"))\n
\n
try: mode = str(context.REQUEST.form["mode"])\n
except KeyError: mode = "generic"\n
......@@ -68,12 +69,12 @@ jio.setMode(mode)\n
\n
try:\n
response_json = jio.putDocumentMetadata(doc, overwrite=False)\n
except ValueError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot post document", str(e)))\n
except TypeError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot post document", str(e)))\n
except LookupError as e:\n
except (ValueError, TypeError, LookupError) as e:\n
return jio.sendError(jio.createConflictDict("Cannot post document", str(e)))\n
# except KeyError as e:\n
# return jio.sendError(jio.createForbiddenDict("Cannot post document", str(e)))\n
# except LookupError as e:\n
# return jio.sendError(jio.createConflictDict("Cannot post document", str(e)))\n
\n
return jio.sendSuccess(response_json)\n
</string> </value>
......
......@@ -67,11 +67,11 @@ except KeyError: mode = "generic"\n
jio.setMode(mode)\n
\n
try:\n
response_json = jio.putDocumentMetadata(doc)\n
except ValueError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot put document", str(e)))\n
except TypeError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot put document", str(e)))\n
response_json = jio.putDocumentMetadata(doc, need_id=True)\n
except (ValueError, TypeError, KeyError) as e:\n
return jio.sendError(jio.createConflictDict("Cannot put document", str(e)))\n
# except KeyError as e:\n
# return jio.sendError(jio.createForbiddenDict("Cannot put document", str(e)))\n
\n
return jio.sendSuccess(response_json)\n
</string> </value>
......
......@@ -68,10 +68,10 @@ jio.setMode(mode)\n
\n
try:\n
response_json = jio.putDocumentAttachment(doc)\n
except ValueError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot put attachment", str(e)))\n
except TypeError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot put attachment", str(e)))\n
except (ValueError, TypeError, KeyError) as e:\n
return jio.sendError(jio.createConflictDict("Cannot put attachment", str(e)))\n
# except TypeError as e:\n
# return jio.sendError(jio.createBadRequestDict("Cannot put attachment", str(e)))\n
\n
return jio.sendSuccess(response_json)\n
</string> </value>
......
......@@ -68,10 +68,10 @@ jio.setMode(mode)\n
\n
try:\n
response_json = jio.removeDocument(doc)\n
except ValueError as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot remove document", str(e)))\n
except TypeError as e:\n
except (ValueError, TypeError) as e:\n
return jio.sendError(jio.createBadRequestDict("Cannot remove document", str(e)))\n
except LookupError as e:\n
return jio.sendError(jio.createNotFoundDict("Cannot remove document", str(e)))\n
\n
return jio.sendSuccess(response_json)\n
</string> </value>
......
......@@ -58,31 +58,22 @@ context.REQUEST.response.setHeader("Access-Control-Allow-Origin", "*")\n
\n
jio = context.JIO_class()\n
\n
try:\n
doc = json.loads(context.REQUEST.form["doc"])\n
except IndexError:\n
return jio.sendError(jio.createBadRequestErrorObject("Unable to operate put request", "No document received"))\n
try:\n
mode = str(context.REQUEST.form["mode"])\n
try: doc = jio.jsonUtf8Loads(context.REQUEST.form["doc"])\n
except KeyError:\n
mode = "normal"\n
return jio.sendError(jio.createBadRequestDict("Cannot get document", "No document information received"))\n
\n
try: mode = str(context.REQUEST.form["mode"])\n
except KeyError: mode = "generic"\n
jio.setMode(mode)\n
\n
doc = jio.recursiveEncodeToUtf8(doc)\n
\n
if not isinstance(doc.get("_id"), str) or doc.get("_id") == "":\n
return jio.sendError(jio.createBadRequestErrorObject("Unable to operate put request", "Document id is missing"))\n
\n
document_list = jio.getDocumentListFromId(doc.get("_id"))\n
\n
if len(document_list) == 0:\n
return jio.sendError(jio.createNotFoundErrorObject("Unable to find \\"" + doc.get("_id") + "\\"", "Document not found"))\n
else:\n
# TODO manage several documents\n
jio.removeAttachment(document_list[0], doc)\n
try:\n
response_json = jio.removeAttachment(doc)\n
except (ValueError, TypeError) as e:\n
return jio.sendError(jio.createConflictDict("Cannot remove attachment", str(e)))\n
except LookupError as e:\n
return jio.sendError(jio.createNotFoundDict("Cannot remove attachment", str(e)))\n
\n
return jio.sendSuccess({"ok": True, "id": doc["_id"], "attachment": doc["_attachment"]})\n
return jio.sendSuccess(response_json)\n
</string> </value>
</item>
<item>
......
2
\ No newline at end of file
3
\ No newline at end of file
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