Commit 3f4ad9df 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 3e5b0754
......@@ -29,7 +29,6 @@ import json
import jsonschema
from erp5.component.document.JSONType import JSONType
from erp5.component.document.TextDocument import TextDocument
import re
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
......@@ -39,8 +38,8 @@ class JSONForm(JSONType, TextDocument):
"""
Represents a form with JSON Form
"""
meta_type = 'ERP5 Text Document'
portal_type = 'JSON Form'
meta_type = "ERP5 Text Document"
portal_type = "JSON Form"
# Declarative security
security = ClassSecurityInfo()
......@@ -68,7 +67,7 @@ class JSONForm(JSONType, TextDocument):
else:
raise ValueError(json.dumps(validation_result))
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"
def validateJSON(self, json_data, list_error=False):
......@@ -90,22 +89,18 @@ class JSONForm(JSONType, TextDocument):
return True
def returnSchema(self, schema, path, REQUEST):
regex = re.compile(r'"\$id": "(([^"])*)"')
result = regex.search(schema)
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)
schema = json.loads(schema)
schema["$id"] = self.absolute_url().strip() + path
if REQUEST is not None:
control = []
control.append( 'max-age=3600' )
control.append( 'private' )
REQUEST.RESPONSE.setHeader('Cache-control', ', '.join( control ) )
return schema
control.append("max-age=3600")
control.append("private")
REQUEST.RESPONSE.setHeader("Cache-control", ", ".join(control))
return json.dumps(schema, indent=2).encode()
security.declarePublic('getOutputJSONSchema')
security.declarePublic("getOutputJSONSchema")
@UnrestrictedMethod
def getOutputJSONSchema(self, REQUEST=None):
"""
......@@ -117,7 +112,7 @@ class JSONForm(JSONType, TextDocument):
REQUEST
)
security.declarePublic('getInputJSONSchema')
security.declarePublic("getInputJSONSchema")
@UnrestrictedMethod
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