Re: Validation and Events

"Kapil Thangavelu" <k_vertigo-5YxZ1of64+Pk/[email protected]> Mon, 25 Sep 2006 13:42:04 -0700
Newsgroups gmane.comp.web.zope.plone.archetypes.devel
Organization ObjectRealms, LLC
Message-ID <[email protected]>
On Mon, 25 Sep 2006 13:18:36 -0700, Martin Aspeli <[email protected]> wrote:

> George Lee wrote:
>> Hi,
>>
>> Is it possible yet to hook in a validator to an Archetypes object using
>> Five/Zope3 events?
>
> That's not so easy - you can easily make some kind of checks based on an
> event, but you'd need a way to signal back that there was some kind of
> validation error. I'm not aware of any framework component that works
> this way at the moment. It may be an interesting design pattern to
> explore, though.
>
>> Related to Martin Aspeli's work on schema-by-interface -- it's clear  
>> how that
>> could be used to add in a validator just for one new field, but not how  
>> we could
>> validate that the data from two fields satisfy some condition (e.g.,  
>> min < max).
>
> mmm... basically, the schema-by-interface work (which will be achieved
> using ContentFlavors - the changes to AT are minimal) it will be just as
> if you'd monkey patched or hand-edited the schema of some class. AT
> validators etc will work as they do now.
>
> If you want to add validators that are not field-specific (e.g. via
> validate_foo() method) then I don't think that's quite in scope.
>
> As Philipp points out, Z3 has its own validation/constraints framework
> which is possibly more appropriate, I haven't really played with it.
>

afaicr, the z3 validation/constraints not appropriate for archetypes  
content, without constructing z3 schema field analogues for at.

an easy way to get whole object constraints validation constraints  
decoupled, is firing event an IValidateModifyContent, in  
baseobject.post_validate method.
i suspect by default existing code with custom validators won't get an  
event validation, unless they call the base object impl or fire the event.

cheers,

kapil



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV