[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/ Implemented
part of
Jim Fulton
jim at zope.com
Mon Apr 25 17:23:44 EDT 2005
Log message for revision 30176:
Implemented part of
http://www.zope.org/Zope3/MoreCleanupOfWidgets
by removing the validate method.
Unfortunately, hasValidInput *is* being used in a somewhat reasonable
way, so I can't get rid of that.
Someday, I really want to remove responsibility for widgets to:
- validate
- apply changes
Changed:
U Zope3/trunk/src/zope/app/form/__init__.py
U Zope3/trunk/src/zope/app/form/browser/tests/test_checkboxwidget.py
U Zope3/trunk/src/zope/app/form/interfaces.py
U Zope3/trunk/src/zope/app/form/tests/test_widget.py
-=-
Modified: Zope3/trunk/src/zope/app/form/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/form/__init__.py 2005-04-25 20:18:45 UTC (rev 30175)
+++ Zope3/trunk/src/zope/app/form/__init__.py 2005-04-25 21:23:43 UTC (rev 30176)
@@ -69,14 +69,11 @@
def hasValidInput(self):
try:
- self.validate()
+ self.getInputValue()
return True
except InputErrors:
return False
- def validate(self):
- self.getInputValue()
-
def applyChanges(self, content):
field = self.context
value = self.getInputValue()
Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_checkboxwidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_checkboxwidget.py 2005-04-25 20:18:45 UTC (rev 30175)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_checkboxwidget.py 2005-04-25 21:23:43 UTC (rev 30176)
@@ -122,7 +122,8 @@
constraint will always be met with checkbox input:
>>> field.required = True
- >>> widget.validate()
+ >>> widget.getInputValue()
+ True
"""
_FieldFactory = Bool
Modified: Zope3/trunk/src/zope/app/form/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/form/interfaces.py 2005-04-25 20:18:45 UTC (rev 30175)
+++ Zope3/trunk/src/zope/app/form/interfaces.py 2005-04-25 21:23:43 UTC (rev 30176)
@@ -161,22 +161,6 @@
a checkbox) to avoid unnecessary 'required' UI notations.
""")
- def validate():
- """Returns a valid value from the widget.
-
- This method returns the data of the field in the native Python
- format. The value is also validated against the field's constraints.
-
- If the field is required and no input was found, a
- ``MissingInputError`` will be raised.
-
- If the field is not required and no input was found, then return the
- ``missing_value`` of the field.
-
- If validation errors occurred, then they are all collected in a new
- ``WidgetInputError`` exception, which is raised.
- """
-
def getInputValue():
"""Return value suitable for the widget's field.
Modified: Zope3/trunk/src/zope/app/form/tests/test_widget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/tests/test_widget.py 2005-04-25 20:18:45 UTC (rev 30175)
+++ Zope3/trunk/src/zope/app/form/tests/test_widget.py 2005-04-25 21:23:43 UTC (rev 30176)
@@ -107,7 +107,7 @@
... pass
>>> widget = TestInputWidget(field, Request(ITestRequest))
- The default implementation of hasValidInput and validate both rely on
+ The default implementation of hasValidInput relies on
getInputValue to perform the validation of the current widget input.
In this simple example, the widget will always raise an error when its
field is read only:
@@ -117,13 +117,6 @@
Traceback (most recent call last):
WidgetInputError: ('', '', None)
- A call to validate, however, accomplishes the same thing with improved
- readability:
-
- >>> widget.validate()
- Traceback (most recent call last):
- WidgetInputError: ('', '', None)
-
A call to hasValidInput returns False instead of raising an error:
>>> widget.hasValidInput()
@@ -136,10 +129,6 @@
>>> widget.getInputValue()
'Foo Bar'
- Correspondingly, validate does not raise an error:
-
- >>> widget.validate()
-
and hasValidInput returns True:
>>> widget.hasValidInput()
More information about the Zope3-Checkins
mailing list