[Zope3-Users] child is not cataloged while adding parent

wata at kke.biglobe.ne.jp wata at kke.biglobe.ne.jp
Wed Mar 22 04:29:11 EST 2006


I think that I figured out what is happening.

this is what I figured out:

(1) zapi.getSizeManager is hooked by
zope.app.component.hooks.getSiteManager,
which returns siteinfo.sm when 'context' argument is None.

(2) so, if I want to use an adapter via getSiteManager(),
I have to set "siteinfo" appropriately before using it.

(3) but I didn't do that, so I got the global site manager instead.


Then, I tried the code looks like below, and it seems worked.

----
class Site(BaseSite):
    
    # this method will be called as a subscriber of ObjectAddedEvent
    def onAfterAdded(self):
        # set siteinfo
        from zope.app.component.hooks import setSite, getSite
        save_site = getSite()
        setSite(self)
        
        # add an index to the catalog
        # (site-manager/intids/catalog are already added by superclass)
        default = self.getSiteManager()['default']
        catalog = default['Catalog']
        catalog['JobTitles'] = FieldIndex(field_name='name',interface=IJobTitle)
        
        # add a container which superclass is OrderedContainer.
        jtf = JobTitleFolder()
        self[u'a'] = jtf
        # add some object to be cataloged
        jtf['P'] = JobTitle('President')
        jtf['VP'] = JobTitle('Vice President')
        
        # resume siteinfo
        setSite(save_site)
----

I used setSite/getSite pair from zope.app.component.hooks .
But I wonder if it is an appropriate solution. 
It would be very helpful to tell me if there is any bad side 
effect from setSite/getSite.



Regards,
Katsutoshi
--
Watanabe, Katsutoshi



More information about the Zope3-users mailing list