[Zope3-checkins] SVN: Zope3/branches/3.3/ - Fixed issue 599: provided view for interface.Invalid

Christian Theune cvs-admin at zope.org
Mon Jun 19 22:58:01 EDT 2006


Log message for revision 68767:
   - Fixed issue 599: provided view for interface.Invalid 
  

Changed:
  U   Zope3/branches/3.3/doc/CHANGES.txt
  U   Zope3/branches/3.3/src/zope/formlib/configure.zcml
  A   Zope3/branches/3.3/src/zope/formlib/errors.py
  A   Zope3/branches/3.3/src/zope/formlib/errors.txt
  A   Zope3/branches/3.3/src/zope/formlib/ftests.py
  U   Zope3/branches/3.3/src/zope/formlib/tests.py

-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt	2006-06-20 00:01:45 UTC (rev 68766)
+++ Zope3/branches/3.3/doc/CHANGES.txt	2006-06-20 02:57:57 UTC (rev 68767)
@@ -10,6 +10,9 @@
 
     Bugfixes
 
+      - Fixed issue 599: Provided a view for interface.exceptions.Invalid to
+        allow formlib to display errors when validating invariants.
+
       - The 'install' generation was hiding ImportErrors that happen within the
         'install' module; they get re-raised now.
 

Modified: Zope3/branches/3.3/src/zope/formlib/configure.zcml
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/configure.zcml	2006-06-20 00:01:45 UTC (rev 68766)
+++ Zope3/branches/3.3/src/zope/formlib/configure.zcml	2006-06-20 02:57:57 UTC (rev 68767)
@@ -16,5 +16,13 @@
       name="template"
       />
 
+  <!-- Error view for 'Invalid' -->
+  <view
+      type="zope.publisher.interfaces.browser.IBrowserRequest"
+      for="zope.interface.exceptions.Invalid"
+      provides="zope.app.form.browser.interfaces.IWidgetInputErrorView"
+      factory=".errors.InvalidErrorView"
+      permission="zope.Public"
+      />
 
 </configure>

Added: Zope3/branches/3.3/src/zope/formlib/errors.py
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/errors.py	2006-06-20 00:01:45 UTC (rev 68766)
+++ Zope3/branches/3.3/src/zope/formlib/errors.py	2006-06-20 02:57:57 UTC (rev 68767)
@@ -0,0 +1,48 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Error related things.
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+from cgi import escape
+
+from zope.interface import implements
+from zope.i18n import translate
+
+from zope.app.form.interfaces import IWidgetInputError
+from zope.app.form.browser.interfaces import IWidgetInputErrorView
+
+class InvalidErrorView(object):
+    """Display a validation error as a snippet of text."""
+    implements(IWidgetInputErrorView)
+
+    __used_for__ = IWidgetInputError
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+
+    def snippet(self):
+        """Convert a widget input error to an html snippet
+
+        >>> from zope.interface.exceptions import Invalid
+        >>> error = Invalid("You made an error!")
+        >>> InvalidErrorView(error, None).snippet()
+        u'<span class="error">You made an error!</span>'
+        """
+        message = str(self.context)
+        translated = translate(message, context=self.request, default=message)
+        return u'<span class="error">%s</span>' % escape(translated)
+


Property changes on: Zope3/branches/3.3/src/zope/formlib/errors.py
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native

Added: Zope3/branches/3.3/src/zope/formlib/errors.txt
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/errors.txt	2006-06-20 00:01:45 UTC (rev 68766)
+++ Zope3/branches/3.3/src/zope/formlib/errors.txt	2006-06-20 02:57:57 UTC (rev 68767)
@@ -0,0 +1,23 @@
+==============
+Error handling
+==============
+
+These are a couple of functional tests that were written on-the-go ... In the
+future this might become more extensive ...
+
+Displaying invalidation errors
+==============================
+
+Validation errors, e.g. cause by invariants, are converted into readable text
+by adapting them to IWidgetInputErrorView:
+
+    >>> from zope.publisher.browser import TestRequest
+    >>> from zope.interface.exceptions import Invalid
+    >>> from zope.component import getMultiAdapter
+    >>> from zope.app.form.browser.interfaces import IWidgetInputErrorView
+    >>> error = Invalid("You are wrong!")
+    >>> message = getMultiAdapter((error, TestRequest()),
+    ...         IWidgetInputErrorView).snippet()
+    >>> message
+    u'<span class="error">You are wrong!</span>'
+


Property changes on: Zope3/branches/3.3/src/zope/formlib/errors.txt
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native

Added: Zope3/branches/3.3/src/zope/formlib/ftests.py
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/ftests.py	2006-06-20 00:01:45 UTC (rev 68766)
+++ Zope3/branches/3.3/src/zope/formlib/ftests.py	2006-06-20 02:57:57 UTC (rev 68767)
@@ -0,0 +1,24 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Functional tests for zope.formlib
+
+"""
+__docformat__ = "reStructuredText"
+
+import unittest
+
+import zope.app.testing.functional
+
+def test_suite():
+    return zope.app.testing.functional.FunctionalDocFileSuite(
+            "errors.txt")


Property changes on: Zope3/branches/3.3/src/zope/formlib/ftests.py
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native

Modified: Zope3/branches/3.3/src/zope/formlib/tests.py
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/tests.py	2006-06-20 00:01:45 UTC (rev 68766)
+++ Zope3/branches/3.3/src/zope/formlib/tests.py	2006-06-20 02:57:57 UTC (rev 68767)
@@ -512,6 +512,8 @@
             'namedtemplate.txt',
             setUp=pageSetUp, tearDown=zope.component.testing.tearDown,
             ),
+        doctest.DocTestSuite(
+            'zope.formlib.errors')
         ))
 
 if __name__ == '__main__':



More information about the Zope3-Checkins mailing list