[Zope3-checkins] CVS: Zope3/src/zope/app/browser/exception -
form.py:1.1
Jim Fulton
jim at zope.com
Thu Aug 7 18:34:36 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/browser/exception
In directory cvs.zope.org:/tmp/cvs-serv479/src/zope/app/browser/exception
Added Files:
form.py
Log Message:
Moved the WidgetInputErrorView here from
src/zope/app/interfaces/form.py. Also added a test.
=== Added File Zope3/src/zope/app/browser/exception/form.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: form.py,v 1.1 2003/08/07 21:34:30 jim Exp $
"""
from zope.app.interfaces.form import IWidgetInputError
from cgi import escape
class WidgetInputErrorView:
"""Displat an input error as a snippet of text"""
__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.interfaces.form import WidgetInputError
>>> err = WidgetInputError("foo", "Foo", ["Foo input < 1"])
>>> view = WidgetInputErrorView(err, None)
>>> view.snippet()
'<span class="error">Foo input < 1</span>'
"""
return '<span class="error">%s</span>' % escape(self.context.errors[0])
More information about the Zope3-Checkins
mailing list