Re: Validation and Events
Martin Aspeli <[email protected]> Mon, 25 Sep 2006 23:11:49 +0100
| Newsgroups | gmane.comp.web.zope.plone.archetypes.devel |
|---|---|
| Message-ID | <[email protected]> |
George Lee wrote:
>> Also - I don't remember whether notify() blocks until all event handlers
>> have completed or not. Presuming it does, that approach could work.
>
> Sorry, can you clarify what you mean here, and what the possible pitfall is?
So:
class IArchetypesValidationEvent(Interface):
object = Attribute('The object being validated')
errors = Attribute('The errors dict')
class ArchetypesValidationEvent(object):
implements(IArchetypesValidationEvent)
def __init__(self, object, errors):
self.object = object
self.errors = errors
def validateMyObject(evt):
if evt.object.foo == bar:
evt.errors['foo'] = "Don't do that"
Now, we'd do:
def post_validate(self, errors):
...
# Let other validators do their magic
notify(ArchetypesValidationEvent(self, errors))
# Did they do anything?
if len(errors) > 0:
return False # we have an error
This is pseudo-code, obviously. But the point is, if notify() didn't
block until all event handlers were finished, then you couldn't check
the 'errors' dict like that!
> I smell a test to write.
Go ahead :)
> Well actually, are there ideas on how to write a test for this validation event?
> It feels complicated.
Something like the above - an event with a handler that mutates
something so that you can check whether the mutation has happened by the
time you reach the code after the call to notify(). Or just trace
notify(). I think it blocks, I'm just not 100% sure.
If you can dig into AT and determine where best to fire this event, we
may try to get this done.
Martin
-------------------------------------------------------------------------
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