[Zope3-Users] zc.relationship or hurry.query and global intid utility

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Jan 6 19:56:16 EST 2007


On Saturday 06 January 2007 13:14, Gabi Shaar wrote:
> could somebody point me at a simple example of how to create the intid
> utility these packages are looking for ?

Here is some code registering the stuff programmatically. Frank already told 
you the correct solution for doing this via the ZMI.

from zope.app import intid
from zope.app.catalog import catalog
from zope.app.component import hooks
from zope.security.proxy import removeSecurityProxy
from zc.catalog import index, catalogindex


        # Get the local site manager
        sm = removeSecurityProxy(self.context.getSiteManager())

        # Create an intid utility
        if 'ids' not in sm['default']:
            ids = intid.IntIds()
            sm['default']['ids' ] = ids
            sm.registerUtility(ids, intid.interfaces.IIntIds)

        # Create a catalog
        ctlg = catalog.Catalog()
        sm['default'][name] = ctlg
        sm.registerUtility(ctlg, zope.app.catalog.interfaces.ICatalog,
                           name=name)

        # Set the site, so that the indices don't go crazy
        originalSite = hooks.getSite()
        hooks.setSite(self.context)

        # Add indices
        ctlg['name'] = catalogindex.ValueIndex('name', IContained)
        ctlg['interfaces'] = InterfacesIndex()

        # Reset the site
        hooks.setSite(originalSite)

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training


More information about the Zope3-users mailing list