Commit 4cfe4a79 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Arnaud Fontaine

py2/py3: make erp5_hal_json_style compatible with Python 3.

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