Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Titouan Soulard
erp5
Commits
6e3eca10
Commit
6e3eca10
authored
Jun 02, 2022
by
Cédric Le Ninivin
Committed by
Titouan Soulard
Mar 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_json_form: Integrate dedicated method to provide clean and cached schemas
parent
124ff9dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
1 deletion
+25
-1
bt5/erp5_json_form/ModuleComponentTemplateItem/portal_components/document.erp5.JSONForm.py
...tTemplateItem/portal_components/document.erp5.JSONForm.py
+25
-1
No files found.
bt5/erp5_json_form/ModuleComponentTemplateItem/portal_components/document.erp5.JSONForm.py
View file @
6e3eca10
...
@@ -29,6 +29,7 @@ import json
...
@@ -29,6 +29,7 @@ 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
...
@@ -73,7 +74,7 @@ class JSONForm(JSONType, TextDocument):
...
@@ -73,7 +74,7 @@ class JSONForm(JSONType, TextDocument):
"""
"""
Validate contained JSON with the Schema defined in the Portal Type.
Validate contained JSON with the Schema defined in the Portal Type.
"""
"""
defined_schema
=
json
.
loads
(
self
.
get
TextContent
()
or
""
)
defined_schema
=
json
.
loads
(
self
.
get
InputJSONSchema
()
or
""
)
try
:
try
:
jsonschema
.
validate
(
json_data
,
defined_schema
,
format_checker
=
jsonschema
.
FormatChecker
())
jsonschema
.
validate
(
json_data
,
defined_schema
,
format_checker
=
jsonschema
.
FormatChecker
())
except
jsonschema
.
exceptions
.
ValidationError
as
err
:
except
jsonschema
.
exceptions
.
ValidationError
as
err
:
...
@@ -86,3 +87,26 @@ class JSONForm(JSONType, TextDocument):
...
@@ -86,3 +87,26 @@ class JSONForm(JSONType, TextDocument):
}
}
return
err
return
err
return
True
return
True
security
.
declarePublic
(
'getInputJSONSchema'
)
def
getInputJSONSchema
(
self
,
REQUEST
=
None
):
"""
Clean way to retrive the schema
* Set proper cache headers
* Properly set the $id property
"""
schema
=
self
.
getTextContent
()
regex
=
re
.
compile
(
r'"\
$id
": "(([^"])*)"'
)
result
=
regex
.
search
(
schema
)
schema_id
=
self
.
absolute_url
().
strip
()
+
"/getInputJSONSchema"
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
:
control
=
[]
control
.
append
(
'max-age=3600'
)
control
.
append
(
'private'
)
REQUEST
.
RESPONSE
.
setHeader
(
'Cache-control'
,
', '
.
join
(
control
)
)
return
schema
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment