[Product-Developers] invariant validator for add form has no context?

David Glick (GW) davidglick at groundwire.org
Thu Jan 19 17:51:50 UTC 2012


On Jan 19, 2012, at 5:38 AM, zjs2k wrote:

> Thanks for the quick reply and the explanation on getSite. I know it works
> but didn't know how it works.
>
> For my purpose, I actually need the container and to confirm their is no
> same content within that container. It is OK to have the same ones
> elsewhere. So the container context of an add form will work.
>
> The method z3c.form.field.FieldWidgets.validate set context to None before
> getting the validator. I wonder if it will harm anything to remove
> "content=None". All I can see is that the validator will need to
> discriminate the context as container in an add form, instead of getting
> None as context.

If nothing else, you can use the approach described under "Validating in action handlers" at http://plone.org/products/dexterity/documentation/manual/schema-driven-forms/customising-form-behaviour/validation (this ties the validation more to the form than to the schema, but it sounds like this add form is a special case anyway).

You can also try aq_parent(request['PUBLISHED']) as a way to get the parent of the published object, which should be the container that the form is a view of in this case.

David


----------
David Glick
 Web Developer
 davidglick at groundwireconsulting.com
 206.286.1235x32

Groundwire Consulting is here.

http://groundwire.org/about/FAQ-gw-consulting




More information about the Product-Developers mailing list