[Zope-CMF] IObjectAdded vs. manage_afterAdd

Doyon, Jean-Francois jdoyon at NRCan.gc.ca
Tue Jan 23 09:07:34 EST 2007


Yeah, I'm not seeing a "zope.component.interfaces.IObjectAdded" ...

I'm really quite certain I've done everything correctly ... The
interface, the registration of the handler, the handler itself and the
five:deprecatedManageAddDelete entry.

Still ... Nothing.

The content class uses __metaclass__ ... Could that be a problem?

class MapServerMap(PortalFolder, PortalContent, CLFMetadataImpl):
    """ Map Server Map Class """

    implements(IMapServerMap)

    __metaclass__ = AutomaticMultilingualProperties

That's the only major difference I see with my tool implementation that
uses IObjectAddedEvent successfully ...

J.F.

-----Original Message-----
From: zope-cmf-bounces+jdoyon=nrcan.gc.ca at lists.zope.org
[mailto:zope-cmf-bounces+jdoyon=nrcan.gc.ca at lists.zope.org] On Behalf Of
Doyon, Jean-Francois
Sent: January 23, 2007 8:16 AM
To: Jens Vagelpohl; Zope-CMF List
Subject: RE: [Zope-CMF] IObjectAdded vs. manage_afterAdd

Yes, well, I didn't show the code for my handler, but it is there:

def added(ob, event):
    """ Create the first page of a Map Text upon creation. """
    print "GOT HERE"
    try:
        if not hasattr(ob.aq_explicit, '1'): ob.invokeFactory('Map
Text', '1')
    except:
        pass

I notice however that your example uses
"zope.component.interfaces.IObjectAdded" vs. mine which uses
"zope.app.container.interfaces.IObjectAddedEvent" ...

Like I said, my event handler works for a tool ... But I guess maybe
that's not the right event registration ... I'll try your examples.

Thanks,

J.F.

-----Original Message-----
From: zope-cmf-bounces at lists.zope.org
[mailto:zope-cmf-bounces at lists.zope.org] On Behalf Of Jens Vagelpohl
Sent: January 22, 2007 6:25 PM
To: Zope-CMF List
Subject: Re: [Zope-CMF] IObjectAdded vs. manage_afterAdd

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 22 Jan 2007, at 21:57, Doyon, Jean-Francois wrote:

> Hello,
>
> I'm trying to use IObjectAdded for an object that looks like this:
>
> class MapServerMap(PortalFolder, PortalContent, CLFMetadataImpl):
>     """ Map Server Map Class """
>
>     implements(IMapServerMap)
>
> Without success ... The event doesn't seem to fire at all.

If you want to react to an event you need to do two things:

- - mark your content item with an interface (you already did this)

- - code up a handler for the event

- - register your handler for the event

Only implementing some interface is not enough. You could have a
function like this somewhere:

def handleEvent(ob, event):
     """ Event subscriber for (IMapServerMap, IObjectAdded) events.
     """
     if event.newParent is not None:
         <do something>

and a registration like this:

   <subscriber
       for=".interfaces.IMapServerMap
            zope.component.interfaces.IObjectAdded"
       handler=".MyModule.handleEvent"
       />

jens


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iD8DBQFFtUexRAx5nvEhZLIRAs64AJ0X3BFyHHvi0t9Xh6PXu9B7owh1CwCgm15n
LB0X4yyOEc9+fU5XQjvjHC8=
=cB8Z
-----END PGP SIGNATURE-----
_______________________________________________
Zope-CMF maillist  -  Zope-CMF at lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests
_______________________________________________
Zope-CMF maillist  -  Zope-CMF at lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


More information about the Zope-CMF mailing list