products/CPSonFive.old

changeset 12:765295c2d375

Overrides the exceptionView
author lregebro
date Mon, 18 Jul 2005 12:55:03 +0000
parents 9cd6679b58ce
children 7d6ae00e86bc
files form/overrides.zcml form/widget.py form/widget_macros.pt
diffstat 3 files changed, 30 insertions(+), 7 deletions(-) [+]
line diff
     1.1 --- a/form/overrides.zcml
     1.2 +++ b/form/overrides.zcml
     1.3 @@ -9,5 +9,13 @@
     1.4      template="widget_macros.pt"
     1.5      permission="zope.Public"
     1.6      />
     1.7 -    
     1.8 +
     1.9 +  <view
    1.10 +    type="zope.publisher.interfaces.browser.IBrowserRequest"
    1.11 +    for="zope.app.form.interfaces.IWidgetInputError"
    1.12 +    provides="zope.app.form.browser.interfaces.IWidgetInputErrorView"
    1.13 +    factory="Products.CPSonFive.form.widget.CPSWidgetInputErrorView"
    1.14 +    permission="zope.Public"
    1.15 +    />
    1.16 +
    1.17  </configure>
     2.1 --- a/form/widget.py
     2.2 +++ b/form/widget.py
     2.3 @@ -18,17 +18,32 @@
     2.4  #
     2.5  # $Id: calendar.py 24398 2005-06-24 12:34:57Z lregebro $
     2.6  
     2.7 +from cgi import escape
     2.8  from zope.app.form.browser import TextWidget
     2.9  from zope.app.form.browser.widget import renderElement
    2.10 -from zope.app.datetimeutils import DateTimeError
    2.11 +from zope.app.form.browser.exception import WidgetInputErrorView
    2.12  from zope.app.form.interfaces import ConversionError, WidgetInputError
    2.13 -from zope.app.form.interfaces import InputErrors
    2.14 -from zope.schema.interfaces import ValidationError
    2.15 +
    2.16  from Products.CMFCore.utils import getToolByName
    2.17 -
    2.18  from zope.i18nmessageid import MessageIDFactory
    2.19  _ = MessageIDFactory("Default")
    2.20  
    2.21 +class CPSWidgetInputErrorView(WidgetInputErrorView):
    2.22 +    """Display an input error as a snippet of text.
    2.23 +
    2.24 +    In Zope 3.0.0, error messages are wrapped in double <span class="error"> 
    2.25 +    tags. This is ugly and complicates translation. We replace these with
    2.26 +    our own error messages that are unwrapped. Another possibility would be 
    2.27 +    to translate them inside this view. That would give us the possibility
    2.28 +    to have different CSS classes for different errors, but we don't need
    2.29 +    that at the moment.
    2.30 +    """
    2.31 +
    2.32 +    def snippet(self):
    2.33 +        """Convert a widget input error to an html snippet"""
    2.34 +        return escape(self.context.doc())
    2.35 +
    2.36 +
    2.37  class DocumentBrowserWidget(TextWidget):
    2.38  
    2.39      displayWidth = 30
     3.1 --- a/form/widget_macros.pt
     3.2 +++ b/form/widget_macros.pt
     3.3 @@ -9,8 +9,8 @@
     3.4        </div>
     3.5        <div class="field">
     3.6          <tal:block tal:content="structure widget"/>
     3.7 -        <span tal:define="error widget/error"
     3.8 -          tal:condition="error" tal:content="structure error"
     3.9 +        <span tal:define="error widget/error" class="error"
    3.10 +          tal:condition="error" tal:content="error"
    3.11            i18n:translate="" >
    3.12            The Error
    3.13          </span>