[Zope3-checkins] CVS: Zope3/src/zope/app/form - interfaces.py:1.1
utility.py:1.28 widget.py:1.14
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Mar 13 16:37:48 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/form
In directory cvs.zope.org:/tmp/cvs-serv6132/src/zope/app/form
Modified Files:
utility.py widget.py
Added Files:
interfaces.py
Log Message:
Moved form interfaces to zope.app.form.interfaces.
=== Added File Zope3/src/zope/app/form/interfaces.py ===
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################
"""Validation Exceptions
$Id: interfaces.py,v 1.1 2004/03/13 21:37:17 srichter Exp $
"""
from zope.schema.interfaces import ValidationError
from zope.component.interfaces import IView
from zope.interface import Attribute, Interface, implements
from zope.app.interfaces.exceptions import UserError
class IWidgetInputError(Interface):
"""Placeholder for a snippet View"""
pass
class WidgetInputError(UserError):
"""There were one or more user input errors
"""
implements(IWidgetInputError)
def __init__(self, field_name, widget_title, errors):
''' errors is a ValidationError '''
UserError.__init__(self, field_name, widget_title, errors)
self.field_name = field_name
self.widget_title = widget_title
self.errors = errors
class MissingInputError(WidgetInputError):
"""Required data was not supplied
"""
class ConversionError(WidgetInputError):
"""If some conversion fails, this exception is raised.
"""
def __init__(self, error_name, original_exception=None):
Exception.__init__(self, error_name, original_exception)
self.error_name = error_name
self.original_exception = original_exception
InputErrors = WidgetInputError, ValidationError
class ErrorContainer(Exception):
"""A base error class for collecting multiple errors.
"""
def append(self, error):
self.args += (error, )
def __len__(self):
return len(self.args)
def __iter__(self):
return iter(self.args)
def __getitem__(self, i):
return self.args[i]
def __str__(self):
return "\n".join(
["%s: %s" % (error.__class__.__name__, error)
for error in self.args]
)
__repr__ = __str__
class WidgetsError(ErrorContainer):
"""A collection of errors from widget processing.
widgetValues is a map containing the list of values that were obtained
from the widget, keyed by field name.
"""
def __init__(self, errors, widgetsData={}):
Exception.__init__(self, *errors)
self.widgetsData = widgetsData
class IWidget(IView):
"""Generically describes the behavior of a widget.
Note that this level must be still presentation independent.
"""
name = Attribute(
"""The uniquewidget name
This must be unique within a set of widgets.""")
title = Attribute(
"""The widget title.
Title may be translated for the request.""")
description = Attribute(
"""The widget description.
Description may be translated for the request.""")
visible = Attribute(
"""A flag indicating whether or not the widget is visible.""")
def setRenderedValue(value):
"""Set the value to be rendered by the widget.
Calling this method will override any values provided by the user.
"""
def setPrefix(prefix):
"""Set the name prefix used for the widget
The widget name is used to identify the widget's data within
input data. For example, for HTTP forms, the widget name is
used for the form key.
"""
class IInputWidget(IWidget):
"""A widget for editing a field value."""
required = Attribute("Flag indicating whether the field is required")
def validate():
"""Validate the widget data.
If there is no user input and the field is required, then a
MissingInputError will be raised.
If there is no user input and the field is not required, then
the field default value will be returned.
A WidgetInputError is returned in the case of one or more
errors encountered, inputting, converting, or validating the data.
"""
def getInputValue():
"""Return value suitable for the widget's field.
The widget must return a value that can be legally assigned to
its bound field or otherwise raise WidgetInputError.
See validate() for validation performed.
"""
def applyChanges(content):
"""Validate the widget data and apply it to the content.
See validate() for validation performed.
"""
def hasInput():
"""Returns True if the widget has input.
Input is used by the widget to calculate an 'input value', which is
a value that can be legally assigned to a field.
Note that the widget may return True, indicating it has input, but
still be unable to return a value from getInputValue. Use
hasValidInput to determine whether or not getInputValue will return
a valid value.
A widget that does not have input should generally not be used to
update its bound field.
"""
def hasValidInput():
"""Returns True is the widget has valid input.
This method is similar to hasInput but it also confirms that the
input provided by the user can be converted to a valid field value
based on the field constraints.
"""
class IDisplayWidget(IWidget):
"""A widget for displaying a field value."""
=== Zope3/src/zope/app/form/utility.py 1.27 => 1.28 ===
--- Zope3/src/zope/app/form/utility.py:1.27 Fri Mar 5 23:17:24 2004
+++ Zope3/src/zope/app/form/utility.py Sat Mar 13 16:37:17 2004
@@ -38,10 +38,10 @@
from zope.schema import getFieldsInOrder
from zope.schema.interfaces import ValidationError
from zope.app import zapi
-from zope.app.interfaces.form import IWidget
-from zope.app.interfaces.form import WidgetsError, MissingInputError
-from zope.app.interfaces.form import InputErrors
-from zope.app.interfaces.form import IInputWidget, IDisplayWidget
+from zope.app.form.interfaces import IWidget
+from zope.app.form.interfaces import WidgetsError, MissingInputError
+from zope.app.form.interfaces import InputErrors
+from zope.app.form.interfaces import IInputWidget, IDisplayWidget
from zope.component.interfaces import IViewFactory
# A marker that indicates 'no value' for any of the utility functions that
=== Zope3/src/zope/app/form/widget.py 1.13 => 1.14 ===
--- Zope3/src/zope/app/form/widget.py:1.13 Mon Mar 8 18:33:59 2004
+++ Zope3/src/zope/app/form/widget.py Sat Mar 13 16:37:17 2004
@@ -17,7 +17,7 @@
import traceback
from warnings import warn
from zope.app import zapi
-from zope.app.interfaces.form import IWidget
+from zope.app.form.interfaces import IWidget
from zope.component.interfaces import IViewFactory
from zope.interface import implements
from zope.i18n import translate
More information about the Zope3-Checkins
mailing list