[Zope3-checkins] CVS: Zope3/src/zope/app/interfaces - form.py:1.5.2.1
Garrett Smith
garrett@mojave-corp.com
Tue, 22 Jul 2003 09:01:40 -0400
Update of /cvs-repository/Zope3/src/zope/app/interfaces
In directory cvs.zope.org:/tmp/cvs-serv26193/src/zope/app/interfaces
Modified Files:
Tag: garrett-widgets-branch
form.py
Log Message:
CVS: ----------------------------------------------------------------------
CVS: Enter Log. Lines beginning with `CVS:' are removed automatically
CVS:
CVS: Committing in .
CVS:
CVS: Modified Files:
CVS: Tag: garrett-widgets-branch
CVS: src/zope/app/browser/cache/cacheable.py
CVS: src/zope/app/browser/component/interfacewidget.py
CVS: src/zope/app/browser/component/tests/test_interfacewidget.py
CVS: src/zope/app/browser/form/editview.py
CVS: src/zope/app/browser/form/vocabularywidget.py
CVS: src/zope/app/browser/form/widget.py
CVS: src/zope/app/browser/form/tests/test_browserwidget.py
CVS: src/zope/app/browser/form/tests/test_checkboxwidget.py
CVS: src/zope/app/browser/form/tests/test_datetimewidget.py
CVS: src/zope/app/browser/form/tests/test_editview.py
CVS: src/zope/app/browser/form/tests/test_floatwidget.py
CVS: src/zope/app/browser/form/tests/test_intwidget.py
CVS: src/zope/app/browser/form/tests/test_objectwidget.py
CVS: src/zope/app/browser/form/tests/test_sequencewidget.py
CVS: src/zope/app/browser/form/tests/test_vocabularywidget.py
CVS: src/zope/app/browser/security/permissionwidget.py
CVS: src/zope/app/browser/services/field.py
CVS: src/zope/app/browser/services/registration/__init__.py
CVS: src/zope/app/browser/services/tests/test_field_widget.py
CVS: src/zope/app/browser/skins/rotterdam/editingwidgets.py
CVS: src/zope/app/dav/configure.zcml src/zope/app/dav/widget.py
CVS: src/zope/app/form/utility.py src/zope/app/form/widget.py
CVS: src/zope/app/form/tests/test_utility.py
CVS: src/zope/app/form/tests/test_widget_geddon_deprecations.py
CVS: src/zope/app/interfaces/form.py
CVS: src/zope/schema/_bootstrapfields.py
CVS: ----------------------------------------------------------------------
Several changes related to widgets:
- Changed haveData to hasData.
- Propogated the use of Field.missing_value as an alternative to
explicit checks for None and '' (empty string).
- Changed the default implementation of hasData (was haveData) to return
True only if the one of the following was true:
- setData had been called for the widget. Per IWidget, values passed to
setData override all other data sources for a widget.
- There is a value in the request form that corresponds to the widget
field.
Prior to this change, hasData would return False if the widget's data
equaled the field's missing value. E.g., a text widget with an empty
string would return False, indicating that it has no data, even though
the empty string, a legitmate value, was submitted in the request.
This change required a handful of other changes to reflect the new
logic.
The bulk of this change effected widget.py. To see how the new logic
implementation of hasData effected widgets, see test_browserwidget.py
and test_utility.py.
- Modified the update logic for objects to skip fields that are not
present in the request form. Prior to this change, unspecified values
(i.e. values not in the request form) would cause default values to be
set for corresponding object fields.
- Exposed missing_value in initializer for Field - developers can now
specify a missing value for a schema field.
- Changed the default implementation of field validation. Prior to this
change, validation failed if a required value was missing. Now validation
is limited to validating non-missing values and the check for required
values is performed elsewhere.
- Text fields have a missing_value of '' (empty string) instead of None.
- Widget related error classes have been revamped:
- WidgetInputError, the base class for all widget related errors, now
provides two attributes: widget, the widget associated with the
error, and error_msg, a string describing the error,
- WidgetInputError implements 'args' so it can be rendered like other
errors.
- MissingInputError uses a standard error message.
- All uses of WidgetInputError and its subclasses have been updated
to use the new class.
- Deleted class zope.app.browser.form.widget.PossiblyEmptyMeansMissing.
This capability is now handled by setting a field's missing_value to ''
(empty string).
- Changed widget's _showData:
- Renamed to getUnconvertedData to clarify the method meaning and signal
its use as a public method.
- Positioned the method as a complement to getData, which returns data
in its converted form. getUnconvertedData returns data in its
unconvereted form using _unconvert.
- Renamed the 'force' argument used in various setUpWidget methods in
utility.py to 'ignore_unspecified'. This argument is set to True to
ensure that fields that are not in a form are not used to update their
corresponding widget. This argument should be true during object
updates (see editview.py) to ensure that unspecified fields are not
updated.
- Removed the 'strict' argument from applyWidgetChanges since no one was
using it and there's no clear application for it.
=== Zope3/src/zope/app/interfaces/form.py 1.5 => 1.5.2.1 ===
--- Zope3/src/zope/app/interfaces/form.py:1.5 Mon Jul 14 11:28:30 2003
+++ Zope3/src/zope/app/interfaces/form.py Tue Jul 22 09:01:06 2003
@@ -16,8 +16,8 @@
$Id$
"""
-import cgi
from zope.schema.interfaces import ValidationError
+from zope.schema.errornames import RequiredMissing
from zope.component.interfaces import IView
from zope.interface import Attribute, Interface, implements
from zope.app.interfaces.exceptions import UserError
@@ -26,39 +26,44 @@
'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
+ def __init__(self, widget, error_msg):
+ """Constructs a WidgetInputError.
+
+ widget is the widget whose input generated the error.
+
+ error_msg is a short, user readable error message.
+ """
+
+ self.widget = widget
+ self.error_msg = error_msg
+ self.args = (widget.name, error_msg)
+
class WidgetInputErrorView:
__used_for__ = IWidgetInputError
def snippet(self):
- return '<span class="error">%s</span>' % self.context.errors[0]
+ return '<span class="error">%s</span>' % self.context.error_msg
+
class MissingInputError(WidgetInputError):
"""Required data was not supplied
"""
+ def __init__(self, widget, error_msg=RequiredMissing):
+ WidgetInputError.__init__(self, widget, error_msg)
+
+
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
@@ -130,7 +135,7 @@
"""
- def haveData():
+ def hasData():
"""Is there input data for the field
Return True if there is data and False otherwise.