Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ayush Tiwari
erp5
Commits
56ca5954
Commit
56ca5954
authored
Sep 25, 2017
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bt5_config: Add functionality for asJSON funtion for JSONRepresentable mixin
parent
e1de4cd0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
product/ERP5/mixin/json_representable.py
product/ERP5/mixin/json_representable.py
+23
-5
No files found.
product/ERP5/mixin/json_representable.py
View file @
56ca5954
...
...
@@ -27,10 +27,13 @@
#
##############################################################################
import
json
import
xmldict
import
zope.interface
from
Products.ERP5.interfaces.json_representable
import
IJSONRepresentable
from
OFS
import
XMLExportImport
from
StringIO
import
StringIO
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5.interfaces.json_representable
import
IJSONRepresentable
from
Products.ERP5Type
import
Permissions
from
Products.ERP5Type.Globals
import
InitializeClass
...
...
@@ -46,11 +49,26 @@ class JSONRepresentableMixin:
security
.
declareObjectProtected
(
Permissions
.
AccessContentsInformation
)
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'asJSON'
)
def
asJSON
():
pass
def
asJSON
(
self
):
"""
Generate a JSON representable content for ERP5 object
Currently we use `asXML` to first convert the object to its XML
respresentation and then use xmltodict to convert it to dict and JSON
format finally
"""
# Use OFS exportXML to first export to xml
f
=
StringIO
()
XMLExportImport
.
exportXML
(
self
.
_p_jar
,
self
.
_p_oid
,
f
)
# Get the value of exported XML
xml_value
=
f
.
getvalue
()
# Convert the XML to json representation
return
json
.
dumps
(
xmldict
.
xml_to_dict
(
xml_value
))
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'fromJSON'
)
def
fromJSON
():
def
fromJSON
(
self
):
pass
InitializeClass
(
JSONRepresentableMixin
)
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