I think that I figured out what is happening.

this is what I figured out:

(1) zapi.getSizeManager is hooked by
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()
        # 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

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.

Watanabe, Katsutoshi

Zope3-users mailing list

Reply via email to