Commit 2021ffd0 authored by Titouan Soulard's avatar Titouan Soulard

erp5_json_form: code style changes

- Update double quotes instead of single quotes
- Avoid using RegEx to update JSON
parent 52a9e045
...@@ -29,7 +29,6 @@ import json ...@@ -29,7 +29,6 @@ import json
import jsonschema import jsonschema
from erp5.component.document.JSONType import JSONType from erp5.component.document.JSONType import JSONType
from erp5.component.document.TextDocument import TextDocument from erp5.component.document.TextDocument import TextDocument
import re
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
...@@ -39,8 +38,8 @@ class JSONForm(JSONType, TextDocument): ...@@ -39,8 +38,8 @@ class JSONForm(JSONType, TextDocument):
""" """
Represents a form with JSON Form Represents a form with JSON Form
""" """
meta_type = 'ERP5 Text Document' meta_type = "ERP5 Text Document"
portal_type = 'JSON Form' portal_type = "JSON Form"
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -68,7 +67,7 @@ class JSONForm(JSONType, TextDocument): ...@@ -68,7 +67,7 @@ class JSONForm(JSONType, TextDocument):
else: else:
raise ValueError(json.dumps(validation_result)) raise ValueError(json.dumps(validation_result))
if self.getAfterMethodId(): if self.getAfterMethodId():
return getattr(getattr(self, 'aq_parent', None), self.getAfterMethodId())(json_data, self) return getattr(getattr(self, "aq_parent", None), self.getAfterMethodId())(json_data, self)
return "Nothing to do" return "Nothing to do"
def validateJSON(self, json_data, list_error=False): def validateJSON(self, json_data, list_error=False):
...@@ -90,22 +89,18 @@ class JSONForm(JSONType, TextDocument): ...@@ -90,22 +89,18 @@ class JSONForm(JSONType, TextDocument):
return True return True
def returnSchema(self, schema, path, REQUEST): def returnSchema(self, schema, path, REQUEST):
regex = re.compile(r'"\$id": "(([^"])*)"') schema = json.loads(schema)
result = regex.search(schema) schema["$id"] = self.absolute_url().strip() + path
schema_id = self.absolute_url().strip() + path
if result:
schema = schema.replace(result.group(1), schema_id, 1)
#print data
else:
schema = schema.replace("{", '{\n "$id": "%s",' % schema_id, 1)
if REQUEST is not None: if REQUEST is not None:
control = [] control = []
control.append( 'max-age=3600' ) control.append("max-age=3600")
control.append( 'private' ) control.append("private")
REQUEST.RESPONSE.setHeader('Cache-control', ', '.join( control ) ) REQUEST.RESPONSE.setHeader("Cache-control", ", ".join(control))
return schema
return json.dumps(schema, indent=2).encode()
security.declarePublic('getOutputJSONSchema') security.declarePublic("getOutputJSONSchema")
@UnrestrictedMethod @UnrestrictedMethod
def getOutputJSONSchema(self, REQUEST=None): def getOutputJSONSchema(self, REQUEST=None):
""" """
...@@ -117,7 +112,7 @@ class JSONForm(JSONType, TextDocument): ...@@ -117,7 +112,7 @@ class JSONForm(JSONType, TextDocument):
REQUEST REQUEST
) )
security.declarePublic('getInputJSONSchema') security.declarePublic("getInputJSONSchema")
@UnrestrictedMethod @UnrestrictedMethod
def getInputJSONSchema(self, REQUEST=None): def getInputJSONSchema(self, REQUEST=None):
""" """
......
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