[Zope3-checkins] CVS: Zope3/src/zope/app/form/browser - exception.py:1.1 configure.zcml:1.3 interfaces.py:1.2 widget.py:1.7

Philipp von Weitershausen philikon at philikon.de
Sun Apr 11 08:32:19 EDT 2004


Update of /cvs-repository/Zope3/src/zope/app/form/browser
In directory cvs.zope.org:/tmp/cvs-serv24636/src/zope/app/form/browser

Modified Files:
	configure.zcml interfaces.py widget.py 
Added Files:
	exception.py 
Log Message:
Moved view for WidgetInputError exception to zope.app.form.browser and
made it a view providing an interface (IWidgetInputErrorView).


=== Added File Zope3/src/zope/app/form/browser/exception.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Form-related exception views

$Id: exception.py,v 1.1 2004/04/11 12:31:48 philikon Exp $
"""
from cgi import escape

from zope.interface import implements

from zope.app.form.interfaces import IWidgetInputError
from zope.app.form.browser.interfaces import IWidgetInputErrorView

class WidgetInputErrorView:
    """Display an input error as a snippet of text."""
    implements(IWidgetInputErrorView)

    __used_for__ = IWidgetInputError

    def __init__(self, context, request):
        self.context, self.request = context, request

    def snippet(self):
        """Convert a widget input error to an html snippet

        >>> from zope.app.form.interfaces import WidgetInputError
        >>> class TooSmallError:
        ...     def doc(self):
        ...         return "Foo input < 1"
        >>> err = WidgetInputError("foo", "Foo", TooSmallError())
        >>> view = WidgetInputErrorView(err, None)
        >>> view.snippet()
        '<span class="error">Foo input &lt; 1</span>'
        """
        return '<span class="error">%s</span>' %(
            escape(self.context.errors.doc()))


=== Zope3/src/zope/app/form/browser/configure.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/form/browser/configure.zcml:1.2	Wed Mar 17 12:35:36 2004
+++ Zope3/src/zope/app/form/browser/configure.zcml	Sun Apr 11 08:31:48 2004
@@ -1,4 +1,14 @@
 <configure xmlns="http://namespaces.zope.org/zope">
+
+  <!-- Views for -->
+
+  <view
+      type="zope.publisher.interfaces.browser.IBrowserRequest"     
+      for="zope.app.form.interfaces.IWidgetInputError"
+      provides="zope.app.form.browser.interfaces.IWidgetInputErrorView"
+      factory="zope.app.form.browser.exception.WidgetInputErrorView"
+      permission="zope.Public"
+      />
    
   <!-- Core display widgets -->
 


=== Zope3/src/zope/app/form/browser/interfaces.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/form/browser/interfaces.py:1.1	Sat Mar 13 20:11:34 2004
+++ Zope3/src/zope/app/form/browser/interfaces.py	Sun Apr 11 08:31:48 2004
@@ -189,3 +189,9 @@
 
         'value' is the current value represented by the widget.
         """
+
+class IWidgetInputErrorView(Interface):
+    """Display an input error as a snippet of text."""
+
+    def snippet():
+        """Convert a widget input error to an html snippet."""


=== Zope3/src/zope/app/form/browser/widget.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/form/browser/widget.py:1.6	Sun Apr 11 06:34:40 2004
+++ Zope3/src/zope/app/form/browser/widget.py	Sun Apr 11 08:31:48 2004
@@ -29,6 +29,7 @@
 from zope.app.form import Widget
 from zope.app.form.interfaces import WidgetInputError, MissingInputError
 from zope.app.form.browser.interfaces import IBrowserWidget
+from zope.app.form.browser.interfaces import IWidgetInputErrorView
 
 class BrowserWidget(Widget, BrowserView):
     """A field widget that knows how to display itself as HTML.
@@ -43,10 +44,12 @@
     >>> from zope.app.publisher.browser import BrowserView
     >>> from cgi import escape
     >>> class SnippetErrorView(BrowserView):
-    ...     def __call__(self):
+    ...     implements(IWidgetInputErrorView)
+    ...     def snippet(self):
     ...         return escape(self.context.errors[0])
     ...
-    >>> ztapi.browserView(IWidgetInputError, 'snippet', SnippetErrorView)
+    >>> ztapi.browserViewProviding(IWidgetInputError, SnippetErrorView,
+    ...                            IWidgetInputErrorView)
     >>> from zope.publisher.browser import TestRequest
 
     And now the tests proper...
@@ -286,7 +289,8 @@
 
     def error(self):
         if self._error:
-            return zapi.getView(self._error, 'snippet', self.request)()
+            return zapi.getViewProviding(self._error, IWidgetInputErrorView,
+                                         self.request).snippet()
         return ""
 
     def labelClass(self):




More information about the Zope3-Checkins mailing list