[Zope-dev] [Checkins] SVN: z3c.form/trunk/ merged branch icemac_validate_NOT_CHANGED
Michael Howitz
mh at gocept.com
Tue May 26 03:10:52 EDT 2009
Am 24.05.2009 um 10:46 schrieb Adam GROSZER:
> Hello Michael,
>
> After some simple thinking there are some fears that this wrecks other
> basic fields validation.
>
> Something like the field is required, has a default value but is
> omitted on input. What will be the result?
When the field is omitted on input it should not have the value
interfaces.NOT_CHANGED but no value, so special handling for
NOT_CHANGED does not apply.
> Accepting the default value
> instead of raising an error is definitely a problem.
>
> Also, values in the system might not be needed to re-validate?
> Image passing around a 100mb uploaded file.
z3c.form has definitely a problem with this use-case. Not only the
validator but also the edit form reads the whole file into RAM.
> If this is meant only for a file upload field, then I think there
> should
> be a special validator registered for those.
interfaces.NOT_CHANGED is currently only used for file uploads, but it
might be used for other fields as well, so I see no reason to put the
handling into a special validator.
> Would be nice to see some (functional) tests closing out the above
> fears.
> Functional, because on the unittest level you can force the widget to
> a lot of unexpected things, but that might not be inline with what
> happens when it's really done by the framework.
> Or better said, revert the changes locally, add those tests, apply the
> changes back and see whether the tests still pass.
File upload fields did not work at all after someone introduced
interfaces.NOT_CHANGED and before adding my changes.
Jacob Holm, who suggested the patch, wrote in http://mail.zope.org/pipermail/zope-dev/2009-April/036258.html
The "code should compute the same value as
z3c.form.widget.Widget.update would when ignoreRequest is True. Thus
effectively converting NOT_CHANGED into the "existing" value before
validating."
> MH> Modified: z3c.form/trunk/src/z3c/form/validator.py
> MH>
> ===================================================================
> MH> --- z3c.form/trunk/src/z3c/form/validator.py 2009-05-17
> 13:18:11 UTC (rev 100027)
> MH> +++ z3c.form/trunk/src/z3c/form/validator.py 2009-05-17
> 13:21:18 UTC (rev 100028)
> MH> @@ -42,9 +42,28 @@
> MH>
> MH> def validate(self, value):
> MH> """See interfaces.IValidator"""
> MH> + context = self.context
> MH> field = self.field
> MH> - if self.context is not None:
> MH> - field = field.bind(self.context)
> MH> + widget = self.widget
> MH> + if context is not None:
> MH> + field = field.bind(context)
> MH> + if value is interfaces.NOT_CHANGED:
> MH> + if (interfaces.IContextAware.providedBy(widget) and
> MH> + not widget.ignoreContext):
> MH> + # get value from context
> MH> + value = zope.component.getMultiAdapter(
> MH> + (context, field),
> MH> + interfaces.IDataManager).query()
> MH> + else:
> MH> + value = interfaces.NO_VALUE
> MH> + if value is interfaces.NO_VALUE:
> MH> + # look up default value
> MH> + value = field.default
> MH> + adapter = zope.component.queryMultiAdapter(
> MH> + (context, self.request, self.view, field,
> widget),
> MH> + interfaces.IValue, name='default')
> MH> + if adapter:
> MH> + value = adapter.get()
> MH> return field.validate(value)
> MH>
> MH> def __repr__(self):
Yours sincerely,
--
Michael Howitz · mh at gocept.com · software developer
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 8 · fax +49 345 1229889 1
Zope and Plone consulting and development
More information about the Zope-Dev
mailing list