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

Shaar Gabriel gabi at shaargiora.co.il
Sun Jan 7 07:21:27 EST 2007


Thanks.
this sorted out a few things in my understanding.

On Sunday 07 January 2007 02:56, Stephan Richter wrote:
> 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


More information about the Zope3-users mailing list