Commit aaeed09f authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components/Python Script: Add link on Zope HTML traceback to go straight...

ZODB Components/Python Script: Add link on Zope HTML traceback to go straight to the source code line.
parent 0391220a
...@@ -414,6 +414,12 @@ ...@@ -414,6 +414,12 @@
ace_editor.getSession().setMode(new PythonMode());\n ace_editor.getSession().setMode(new PythonMode());\n
ace_editor.getSession().setUseSoftTabs(true);\n ace_editor.getSession().setUseSoftTabs(true);\n
ace_editor.getSession().setTabSize(2);\n ace_editor.getSession().setTabSize(2);\n
\n
var href_line_array = /.*?[^#]*line=(\\d+)/.exec(window.location.href)\n
if(href_line_array && href_line_array.length == 2) {\n
ace_editor.focus();\n
ace_editor.gotoLine(href_line_array[1], 0, false);\n
}\n
\n \n
ace.require(\'ace/ext/language_tools\');\n ace.require(\'ace/ext/language_tools\');\n
ace_editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true });\n ace_editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true });\n
......
2014-02-25 arnaud.fontaine
* Allow to specify the line to go to from URL parameter.
2014-02-24 arnaud.fontaine 2014-02-24 arnaud.fontaine
* Add annotations support to check source code without saving. * Add annotations support to check source code without saving.
......
20 21
\ No newline at end of file \ No newline at end of file
...@@ -112,6 +112,12 @@ $(document).ready(function() { ...@@ -112,6 +112,12 @@ $(document).ready(function() {
} }
editor.getSession().setValue(textarea.val()); editor.getSession().setValue(textarea.val());
var href_line_array = /.*?[^#]*line=(\d+)/.exec(window.location.href)
if(href_line_array && href_line_array.length == 2) {
editor.focus();
editor.gotoLine(href_line_array[1], 0, false);
}
editor.getSession().on('change', function(){ editor.getSession().on('change', function(){
textarea.val(editor.getSession().getValue()); textarea.val(editor.getSession().getValue());
if (!beforeunload_warning_set) { if (!beforeunload_warning_set) {
......
...@@ -49,3 +49,50 @@ def formatLine(self, tb, *args, **kwargs): ...@@ -49,3 +49,50 @@ def formatLine(self, tb, *args, **kwargs):
return line_str return line_str
TextExceptionFormatter.formatLine = formatLine TextExceptionFormatter.formatLine = formatLine
from zExceptions.ExceptionFormatter import HTMLExceptionFormatter
HTMLExceptionFormatter_formatLine = HTMLExceptionFormatter.formatLine
def formatLine(self, tb, *args, **kwargs):
"""
Monkey patched to add links to ZODB Components and Python Script. The
regex part is a bit dirty but there is no other way besides of a copy/paste
of formatLine()...
"""
f = tb.tb_frame
filename = f.f_code.co_filename.replace('<', '').replace('>', '')
lineno = tb.tb_lineno
f_globals = f.f_globals
line_str = HTMLExceptionFormatter_formatLine(self, tb, *args, **kwargs)
from Products.ERP5.ERP5Site import getSite
try:
portal_absolute_url = getSite().absolute_url()
import re
# Use the supplement defined in the module.
# This is used by Scripts (Python).
if '__traceback_supplement__' in f_globals:
tbs = f_globals['__traceback_supplement__']
line_str = re.sub(
'^(<li>\s*)(Module script,[^<]*)(.*)$',
r'\1<a href="%s/manage_main?line=%s">\2</a>\3' % (tbs[1].absolute_url(),
lineno),
line_str,
flags=re.DOTALL)
else:
line_str = re.sub(
'^(<li>\s*)(Module erp5\.component\.[^<]*)(.*)$',
r'\1<a href="/%s/%s?line=%s">\2</a>\3' % (portal_absolute_url,
filename,
lineno),
line_str,
flags=re.DOTALL)
except Exception, e:
pass
return line_str
HTMLExceptionFormatter.formatLine = formatLine
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