[Zope3-checkins] SVN: Zope3/trunk/src/zope/formlib/ - ported fix
for issue 599 from 3.3 branch (provides a view for
interface.exceptions.Invalid)
Christian Theune
cvs-admin at zope.org
Mon Jun 19 22:59:40 EDT 2006
Log message for revision 68768:
- ported fix for issue 599 from 3.3 branch (provides a view for interface.exceptions.Invalid)
Changed:
U Zope3/trunk/src/zope/formlib/configure.zcml
A Zope3/trunk/src/zope/formlib/errors.py
A Zope3/trunk/src/zope/formlib/errors.txt
A Zope3/trunk/src/zope/formlib/ftests.py
U Zope3/trunk/src/zope/formlib/tests.py
-=-
Modified: Zope3/trunk/src/zope/formlib/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/formlib/configure.zcml 2006-06-20 02:57:57 UTC (rev 68767)
+++ Zope3/trunk/src/zope/formlib/configure.zcml 2006-06-20 02:59:37 UTC (rev 68768)
@@ -14,5 +14,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/trunk/src/zope/formlib/errors.py
===================================================================
--- Zope3/trunk/src/zope/formlib/errors.py 2006-06-20 02:57:57 UTC (rev 68767)
+++ Zope3/trunk/src/zope/formlib/errors.py 2006-06-20 02:59:37 UTC (rev 68768)
@@ -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/trunk/src/zope/formlib/errors.py
___________________________________________________________________
Name: svn:keywords
+ Id Rev Date
Name: svn:eol-style
+ native
Added: Zope3/trunk/src/zope/formlib/errors.txt
===================================================================
--- Zope3/trunk/src/zope/formlib/errors.txt 2006-06-20 02:57:57 UTC (rev 68767)
+++ Zope3/trunk/src/zope/formlib/errors.txt 2006-06-20 02:59:37 UTC (rev 68768)
@@ -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/trunk/src/zope/formlib/errors.txt
___________________________________________________________________
Name: svn:keywords
+ Id Rev Date
Name: svn:eol-style
+ native
Added: Zope3/trunk/src/zope/formlib/ftests.py
===================================================================
--- Zope3/trunk/src/zope/formlib/ftests.py 2006-06-20 02:57:57 UTC (rev 68767)
+++ Zope3/trunk/src/zope/formlib/ftests.py 2006-06-20 02:59:37 UTC (rev 68768)
@@ -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/trunk/src/zope/formlib/ftests.py
___________________________________________________________________
Name: svn:keywords
+ Id Rev Date
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/formlib/tests.py
===================================================================
--- Zope3/trunk/src/zope/formlib/tests.py 2006-06-20 02:57:57 UTC (rev 68767)
+++ Zope3/trunk/src/zope/formlib/tests.py 2006-06-20 02:59:37 UTC (rev 68768)
@@ -554,6 +554,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