Commit 53004051 authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: BusinessTemplate_getPythonSourceCodeMessageList.

parent 10ad0fce
"""Return python source code in business template """Return python source code in business template
""" """
import json import json
import six
class Message: class Message:
"""A python code linter message, with a link to edit the source code. """A python code linter message, with a link to edit the source code.
...@@ -50,11 +51,14 @@ def checkPythonScript(script_instance, script_path): ...@@ -50,11 +51,14 @@ def checkPythonScript(script_instance, script_path):
# RestrictedPython.Utilities.utility_builtins # RestrictedPython.Utilities.utility_builtins
extra_builtins = ['printed', 'same_type', 'string', 'sequence', 'random', extra_builtins = ['printed', 'same_type', 'string', 'sequence', 'random',
'DateTime', 'whrandom', 'reorder', 'sets', 'test', 'math'] 'DateTime', 'whrandom', 'reorder', 'sets', 'test', 'math']
code = script_instance.body()
if six.PY2:
code = unicode(code, 'utf8')
for annotation in json.loads(portal.ERP5Site_checkPythonSourceCodeAsJSON( for annotation in json.loads(portal.ERP5Site_checkPythonSourceCodeAsJSON(
{'bound_names': extra_builtins + {'bound_names': extra_builtins +
script_instance.getBindingAssignments().getAssignedNamesInOrder(), script_instance.getBindingAssignments().getAssignedNamesInOrder(),
'params': script_instance.params(), 'params': script_instance.params(),
'code': unicode(script_instance.body(), 'utf8') 'code': code
}))['annotations']: }))['annotations']:
annotation["script_path"] = script_path annotation["script_path"] = script_path
line_list.append( line_list.append(
...@@ -74,8 +78,11 @@ def checkComponent(component_instance): ...@@ -74,8 +78,11 @@ def checkComponent(component_instance):
message=consistency_message.getMessage().translate(), message=consistency_message.getMessage().translate(),
edit_url=component_relative_url, edit_url=component_relative_url,
jio_key=component_relative_url,),) jio_key=component_relative_url,),)
code = component_instance.getTextContent()
if six.PY2:
code = unicode(code, 'utf8')
for annotation in json.loads(portal.ERP5Site_checkPythonSourceCodeAsJSON( for annotation in json.loads(portal.ERP5Site_checkPythonSourceCodeAsJSON(
{'code': unicode(component_instance.getTextContent(), 'utf8')}))['annotations']: {'code': code}))['annotations']:
annotation['component_path'] = component_relative_url annotation['component_path'] = component_relative_url
line_list.append( line_list.append(
Message( Message(
......
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