Commit caa6122c authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Arnaud Fontaine

py2/py3: make erp5_hal_json_style compatible with Python 3.

parent 20986cf8
......@@ -15,16 +15,17 @@ There are runtime values hidden in every dialog form (injected by getHateoas Scr
from erp5.component.module.Log import log, WARNING
from Products.Formulator.Errors import FormValidationError
import json
import six
# http://stackoverflow.com/a/13105359
def byteify(value):
if isinstance(value, dict):
return {byteify(key): byteify(value) for key, value in value.iteritems()}
return {byteify(key): byteify(value) for key, value in six.iteritems(value)}
elif isinstance(value, list):
return [byteify(element) for element in value]
elif isinstance(value, tuple):
return tuple(byteify(element) for element in value)
elif isinstance(value, unicode):
elif six.PY2 and isinstance(value, six.text_type):
return value.encode('utf-8')
else:
return value
......
......@@ -6,8 +6,9 @@ Return JSON with message to be displayed and set according HTTP STATUS for messa
"""
import json
from erp5.component.module.Log import WARNING, ERROR
import six
if isinstance(level, (str, unicode)):
if isinstance(level, (str, six.text_type)):
if level.lower() == "error":
response_code = 500
elif level.lower().startswith("warn"):
......
......@@ -3,6 +3,7 @@ from Products.Formulator.Errors import FormValidationError
from Products.ERP5Type.Core.Workflow import ValidationFailed
from Products.ERP5Type.Message import translateString
from erp5.component.module.Log import WARNING
import six
portal = context.getPortalObject()
request = REQUEST or context.REQUEST
......@@ -43,7 +44,7 @@ for f in form.get_fields():
listbox = request.get('listbox') # XXX: hardcoded field name
if listbox is not None:
listbox_line_list = []
for key, value in sorted(listbox.iteritems()):
for key, value in sorted(six.iteritems(listbox)):
value['listbox_key'] = key
listbox_line_list.append(value)
doaction_param_list['listbox'] = tuple(listbox_line_list)
......
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