[Zope-dev] Events and interfaces for different request types

Robert Marianski rmarianski at openplans.org
Wed Sep 10 17:45:50 EDT 2008


On Wed, Sep 10, 2008 at 06:25:20PM -0200, Sidnei da Silva wrote:
> Hi all,
> 
> More than once I've found myself on a situation where I needed to
> subscribe to a specific event but only if it happens through a
> specific request type. One problem with that is that commonly the
> request is not part of the event information. Another problem might be
> that the request type might not be properly flagged, but this is a
> different subject and applies mostly to Zope 2.
> 
> Now, for solving this problem, I usually create a custom and more
> specialized event that includes the request as part of it's
> information. So, for example, I'm interested in IObjectModifiedEvent
> but only for IWebDAVRequest, then I create:
> 
> class IObjectRequestModifiedEvent(IObjectModifiedEvent):
>    request = Attribute(...)
> 
> def subscriber(object, event):
>    if IWebDAVRequest.isProvidedBy(event.request):
>       # do something
> 
> Now, I wonder if someone has any suggestion on how to simplify this further...
> -- 
> Sidnei da Silva
> Enfold Systems http://enfoldsystems.com
> Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214

I haven't tried this, but you might be able to send out an event on an
additional channel in a general handler. Something like:

def subscriber(object, event):
    notify(object, event, event.request)

And you should be able to register event handlers for the 3 channels now.

-- 
Robert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20080910/2f7404df/attachment.bin 


More information about the Zope-Dev mailing list