From e6cacd10ddc6d1e393c454cba889d9d3cc9c8498 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Wed, 26 Jun 2013 17:06:06 +0200 Subject: [PATCH] [px] Better error reporting when encountering a parsing error in a PX. --- gen/mixins/ToolMixin.py | 4 +- gen/ui/appy.js | 5 + gen/wrappers/__init__.py | 319 +++++++++++++++++++++++++++------------ px/__init__.py | 22 ++- 4 files changed, 248 insertions(+), 102 deletions(-) diff --git a/gen/mixins/ToolMixin.py b/gen/mixins/ToolMixin.py index 82ffdac..7973c58 100644 --- a/gen/mixins/ToolMixin.py +++ b/gen/mixins/ToolMixin.py @@ -269,9 +269,9 @@ class ToolMixin(BaseMixin): '''When must the portlet be shown?''' # Not on 'edit' pages. if layoutType == 'edit': return - if context.id == 'ui': context = context.getParentNode() + if context and (context.id == 'ui'): context = context.getParentNode() res = True - if hasattr(context.aq_base, 'appy'): + if context and hasattr(context.aq_base, 'appy'): appyObj = context.appy() try: res = appyObj.showPortlet() diff --git a/gen/ui/appy.js b/gen/ui/appy.js index 2974a17..f892ddd 100644 --- a/gen/ui/appy.js +++ b/gen/ui/appy.js @@ -41,6 +41,11 @@ function showLoginForm() { loginFields.style.display = "inline"; } +function switchLanguage(selectWidget) { + var language = selectWidget.options[selectWidget.selectedIndex].value; + window.location = "/config/changeLanguage?language=" + language; +} + var isIe = (navigator.appName == "Microsoft Internet Explorer"); function getElementsHavingName(tag, name) { diff --git a/gen/wrappers/__init__.py b/gen/wrappers/__init__.py index d9f68f5..1470af1 100644 --- a/gen/wrappers/__init__.py +++ b/gen/wrappers/__init__.py @@ -27,6 +27,131 @@ class AbstractWrapper(object): '''Any real Appy-managed Zope object has a companion object that is an instance of this class.''' + pxPhases = Px('''

Phases

+ ''') + + pxPortlet = Px(''' + + + :self.pxPhases + + + + + +
+ + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + +
+
+ + +
+ :text... +
+
+ + + + + + + + + + + + +
+
+
+ ''') + + pxMessage = Px(''' + +
+ + + + ::messages +
+
+ ''') + + pxFooter = Px(''' + + + + + ''') + pxTemplate = Px(''' + value=":_('object_cancel')"/> @@ -127,10 +252,9 @@ class AbstractWrapper(object): - @@ -138,101 +262,98 @@ class AbstractWrapper(object): - - - :content + + + +
:self.pxMessage
+ + + + + + + + + + + + + +
+ + + + + + + +
+ + + + + + + + + + :userInfo[0] + + +
+
+ + + + + + + + + + + + + + + + + + +
:self.pxPortlet:content
+ + + + :self.pxFooter + ''', prologue=Px.xhtmlPrologue) diff --git a/px/__init__.py b/px/__init__.py index 4dd523d..cd278c2 100644 --- a/px/__init__.py +++ b/px/__init__.py @@ -3,6 +3,7 @@ Python and XML.''' # ------------------------------------------------------------------------------ +import xml.sax from px_parser import PxParser, PxEnvironment from appy.pod.buffers import MemoryBuffer @@ -45,13 +46,32 @@ class Px: self.parser = PxParser(PxEnvironment(), self) # Parses self.content (a PX code in a string) with self.parser, to # produce a tree of memory buffers. - self.parser.parse(self.content) + try: + self.parser.parse(self.content) + except xml.sax.SAXParseException, spe: + self.completeErrorMessage(spe) + raise spe # Is this PX based on a template PX? self.template = template self.hook = hook # Is there some (XML, XHTML...) prologue to dump? self.prologue = prologue + def completeErrorMessage(self, parsingError): + '''A p_parsingError occurred. Complete the error message with the + erroneous line from self.content.''' + # Split lines from self.content + splitted = self.content.split('\n') + i = parsingError.getLineNumber() - 1 + # Get the erroneous line, and add a subsequent line for indicating + # the erroneous column. + column = ' ' * (parsingError.getColumnNumber()-1) + '^' + lines = [splitted[i], column] + # Get the previous and next lines when present. + if i > 0: lines.insert(0, splitted[i-1]) + if i < len(splitted)-1: lines.append(splitted[i+1]) + parsingError._msg += '\n%s' % '\n'.join(lines) + def __call__(self, context, applyTemplate=True): '''Renders the PX.