[Zope3-checkins] CVS: Zope3/src/zope/schema - _bootstrapfields.py:1.19.2.1

Garrett Smith garrett@mojave-corp.com
Tue, 22 Jul 2003 09:01:13 -0400


Update of /cvs-repository/Zope3/src/zope/schema
In directory cvs.zope.org:/tmp/cvs-serv26193/src/zope/schema

Modified Files:
      Tag: garrett-widgets-branch
	_bootstrapfields.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/schema/_bootstrapfields.py 1.19 => 1.19.2.1 ===
--- Zope3/src/zope/schema/_bootstrapfields.py:1.19	Sun Jul 13 02:47:28 2003
+++ Zope3/src/zope/schema/_bootstrapfields.py	Tue Jul 22 09:01:09 2003
@@ -48,6 +48,9 @@
     # value to use
     missing_value = None
 
+    # use in initializer to avoid overwriting class attr
+    _missing_value_marker = object()
+
     # Note that the "order" field has a dual existance:
     # 1. The class variable Field.order is used as a source for the
     #    monotonically increasing values used to provide...
@@ -60,8 +63,13 @@
     default = ValidatedProperty('default')
 
     def __init__(self, __name__='', __doc__='',
-                 title=u'', description=u'',
-                 required=True, readonly=False, constraint=None, default=None,
+                 title=u'', 
+                 description=u'',
+                 required=True, 
+                 readonly=False, 
+                 constraint=None, 
+                 default=None,
+                 missing_value=_missing_value_marker
                  ):
         """Pass in field values as keyword parameters."""
 
@@ -82,6 +90,8 @@
         if constraint is not None:
             self.constraint = constraint
         self.default = default
+        if missing_value is not self._missing_value_marker:
+            self.missing_value = missing_value
 
         # Keep track of the order of field definitions
         Field.order += 1
@@ -94,10 +104,7 @@
         return clone
 
     def validate(self, value):
-        if value is None:
-            if self.required:
-                raise ValidationError(errornames.RequiredMissing)
-        else:
+        if value != self.missing_value:
             try:
                 self._validate(value)
             except StopValidation:
@@ -283,6 +290,8 @@
 class Text(Enumerated, MinMaxLen, Field):
     """A field containing text used for human discourse."""
     _type = unicode
+
+    missing_value = ''
 
     def __init__(self, *args, **kw):
         if (  kw.get("allowed_values") is not None