[Checkins] SVN: z3c.form/branches/adamg-missing-terms/ work around some validation exceptions
Adam Groszer
cvs-admin at zope.org
Wed Sep 12 12:23:23 UTC 2012
Log message for revision 127832:
work around some validation exceptions
Changed:
U z3c.form/branches/adamg-missing-terms/CHANGES.txt
U z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.py
U z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.txt
U z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.zcml
-=-
Modified: z3c.form/branches/adamg-missing-terms/CHANGES.txt
===================================================================
--- z3c.form/branches/adamg-missing-terms/CHANGES.txt 2012-09-12 11:52:05 UTC (rev 127831)
+++ z3c.form/branches/adamg-missing-terms/CHANGES.txt 2012-09-12 12:23:20 UTC (rev 127832)
@@ -13,6 +13,7 @@
with an EditForm after save as it was before editing.
That brings some changes with it:
- *MAJOR*: unchanged values/fields do not get validated anymore
+ (unless they are empty or are FileUploads)
- A temporary ``SimpleTerm`` gets created for the missing value
Title is by default "Missing: ${value}". See MissingTermsMixin.
Modified: z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.py
===================================================================
--- z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.py 2012-09-12 11:52:05 UTC (rev 127831)
+++ z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.py 2012-09-12 12:23:20 UTC (rev 127832)
@@ -89,6 +89,11 @@
def validate(self, value, force=False):
"""See interfaces.IValidator"""
+ if value is self.field.missing_value:
+ # let missing values run into stricter validation
+ # most important case is not let required fields pass
+ return super(SimpleFieldValidator, self).validate(value, force)
+
if not force:
if value is interfaces.NOT_CHANGED:
# no need to validate unchanged values
@@ -100,9 +105,23 @@
return
# otherwise StrictSimpleFieldValidator will do the job
- return super(SimpleFieldValidator, self).validate(value)
+ return super(SimpleFieldValidator, self).validate(value, force)
+class FileUploadValidator(StrictSimpleFieldValidator):
+ """File upload validator
+ """
+ zope.component.adapts(
+ zope.interface.Interface,
+ zope.interface.Interface,
+ zope.interface.Interface,
+ zope.schema.interfaces.IBytes,
+ interfaces.IFileWidget)
+ # only FileUploadDataConverter seems to use NOT_CHANGED, but that needs
+ # to be validated, because file upload is a special case
+ # the most special case if when an ad-hoc IBytes field is required
+
+
def WidgetValidatorDiscriminators(
validator, context=None, request=None, view=None, field=None, widget=None):
zope.component.adapter(
@@ -126,6 +145,7 @@
"""
+
class Data(object):
zope.interface.implements(interfaces.IData)
Modified: z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.txt
===================================================================
--- z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.txt 2012-09-12 11:52:05 UTC (rev 127831)
+++ z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.txt 2012-09-12 12:23:20 UTC (rev 127832)
@@ -74,7 +74,8 @@
... login = zope.schema.TextLine(
... title=u'Login',
... min_length=1,
- ... max_length=10)
+ ... max_length=10,
+ ... required=True)
...
... email = zope.schema.TextLine(
... title=u'E-mail')
@@ -186,7 +187,7 @@
... interfaces.IValidator)
Ignoring unchanged values
-~~~~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~~~
Most of the time we want to ignore unchanged fields/values at validation.
A common usecase for this is if a value went away from a vocabulary and we want
@@ -242,7 +243,16 @@
...
TooLong: (u'hippocratiusxy', 10)
+Some exceptions:
+``missing_value`` gets validated
+
+ >>> simple.validate(IPerson['login'].missing_value)
+ Traceback (most recent call last):
+ ...
+ RequiredMissing: login
+
+
Widget Validators and File-Uploads
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Modified: z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.zcml
===================================================================
--- z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.zcml 2012-09-12 11:52:05 UTC (rev 127831)
+++ z3c.form/branches/adamg-missing-terms/src/z3c/form/validator.zcml 2012-09-12 12:23:20 UTC (rev 127832)
@@ -7,6 +7,9 @@
factory=".validator.SimpleFieldValidator"
/>
<adapter
+ factory=".validator.FileUploadValidator"
+ />
+ <adapter
factory=".validator.InvariantsValidator"
/>
More information about the checkins
mailing list