[Checkins] SVN: z3c.form/trunk/ merged gocept-invariants branch
from r80186 to HEAD
Michael Howitz
mh+zope at gocept.com
Tue Oct 30 04:08:30 EDT 2007
Log message for revision 81198:
merged gocept-invariants branch from r80186 to HEAD
Changed:
U z3c.form/trunk/CHANGES.txt
U z3c.form/trunk/setup.py
U z3c.form/trunk/src/z3c/form/field.py
U z3c.form/trunk/src/z3c/form/validator.py
U z3c.form/trunk/src/z3c/form/validator.txt
-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt 2007-10-30 07:06:28 UTC (rev 81197)
+++ z3c.form/trunk/CHANGES.txt 2007-10-30 08:08:29 UTC (rev 81198)
@@ -2,6 +2,14 @@
CHANGES
=======
+
+After Version 1.7.0
+-------------------
+
+- Bug: Interface invariants where not working when not all fields
+ needed for computing the invariant are in the submitted form.
+
+
Version 1.7.0 (2007-10-09)
--------------------------
Modified: z3c.form/trunk/setup.py
===================================================================
--- z3c.form/trunk/setup.py 2007-10-30 07:06:28 UTC (rev 81197)
+++ z3c.form/trunk/setup.py 2007-10-30 08:08:29 UTC (rev 81198)
@@ -75,7 +75,8 @@
namespace_packages = ['z3c'],
extras_require = dict(
test = ['zope.app.container', 'zope.testing',
- 'z3c.coverage', 'z3c.template'],
+ 'z3c.coverage', 'z3c.template',
+ 'zope.app.i18n', ],
adding = ['zope.app.container'],
),
install_requires = [
Modified: z3c.form/trunk/src/z3c/form/field.py
===================================================================
--- z3c.form/trunk/src/z3c/form/field.py 2007-10-30 07:06:28 UTC (rev 81197)
+++ z3c.form/trunk/src/z3c/form/field.py 2007-10-30 08:08:29 UTC (rev 81198)
@@ -202,9 +202,12 @@
# Step 2: Validate the individual schemas and collect errors
errors = ()
+ content = self.content
+ if self.ignoreContext:
+ content = None
for schema, fieldData in schemaData.items():
validator = zope.component.getMultiAdapter(
- (self.content, self.request, self.form, schema, self),
+ (content, self.request, self.form, schema, self),
interfaces.IManagerValidator)
errors += validator.validate(fieldData)
Modified: z3c.form/trunk/src/z3c/form/validator.py
===================================================================
--- z3c.form/trunk/src/z3c/form/validator.py 2007-10-30 07:06:28 UTC (rev 81197)
+++ z3c.form/trunk/src/z3c/form/validator.py 2007-10-30 08:08:29 UTC (rev 81198)
@@ -99,7 +99,11 @@
# Try to get the value for the field
value = data.get(name, data)
if value is data:
- raise NoInputData(name)
+ if self.__context__ is None:
+ raise NoInputData(name)
+ dm = zope.component.getMultiAdapter(
+ (self.__context__, field), interfaces.IDataManager)
+ value = dm.get()
# Optimization: Once we now we have a good value, set it as an
# attribute for faster access.
setattr(self, name, value)
Modified: z3c.form/trunk/src/z3c/form/validator.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/validator.txt 2007-10-30 07:06:28 UTC (rev 81197)
+++ z3c.form/trunk/src/z3c/form/validator.txt 2007-10-30 08:08:29 UTC (rev 81198)
@@ -205,6 +205,7 @@
or an object implementing the schema:
>>> class Person(object):
+ ... zope.interface.implements(IPerson)
... login = u'srichter'
... email = u'srichter at foo.com'
>>> stephan = Person()
@@ -249,7 +250,7 @@
... print e.__class__.__name__ + ':', e
Invalid: Email too long.
-To register the custom validator only for this schema, we hace to use the
+To register the custom validator only for this schema, we have to use the
discriminator generator again.
>>> from z3c.form import util
@@ -324,3 +325,22 @@
context of validation, for example to look up a vocabulary or access the
parent of an object. Note that the context will be different between add and
edit forms.
+
+Validation of interface variants when not all fields are displayed in form
+--------------------------------------------------------------------------
+
+We need to register the data manager to access the data on the context object:
+
+ >>> from z3c.form import datamanager
+ >>> zope.component.provideAdapter(datamanager.AttributeField)
+
+Sometimes you might leave out fields in the form which need to compute the
+invariant. An exception should be raised. The data wrapper is used to test
+the invariants and looks up values on the context object that are left out in
+the form.
+
+ >>> invariants = validator.InvariantsValidator(
+ ... stephan, None, None, IPerson, None)
+ >>> invariants.validate({'email': 'foo at bar.com'})
+ (<zope.interface.exceptions.Invalid instance at ...>,)
+
More information about the Checkins
mailing list