[Checkins] SVN: grok/branches/faassen-index/src/grok/ Fix a bug in
catalog lookup in the subscriber. This meant multiple
Martijn Faassen
faassen at infrae.com
Fri Apr 20 10:34:34 EDT 2007
Log message for revision 74262:
Fix a bug in catalog lookup in the subscriber. This meant multiple
sets of indexes weren't registered properly.
Changed:
A grok/branches/faassen-index/src/grok/ftests/catalog/indexes_multiple.py
U grok/branches/faassen-index/src/grok/meta.py
-=-
Added: grok/branches/faassen-index/src/grok/ftests/catalog/indexes_multiple.py
===================================================================
--- grok/branches/faassen-index/src/grok/ftests/catalog/indexes_multiple.py 2007-04-20 14:32:04 UTC (rev 74261)
+++ grok/branches/faassen-index/src/grok/ftests/catalog/indexes_multiple.py 2007-04-20 14:34:33 UTC (rev 74262)
@@ -0,0 +1,76 @@
+"""
+Grok allows you to set up catalog indexes in your application with a
+special indexes declaration. In fact, we have multiple grok.Indexes
+setting up more than one set of indexes in the same catalog.
+
+ >>> import grok
+ >>> grok.grok('grok.ftests.catalog.indexes_multiple')
+
+Let's set up a site in which we manage a couple of objects::
+
+ >>> from grok.ftests.catalog.indexes_multiple import Herd
+ >>> herd = Herd()
+ >>> getRootFolder()['herd'] = herd
+ >>> from zope.app.component.hooks import setSite
+ >>> setSite(herd)
+
+We are able to query the catalog::
+
+ >>> from zope.app.catalog.interfaces import ICatalog
+ >>> from zope.component import getUtility, queryUtility
+ >>> catalog = getUtility(ICatalog)
+ >>> sorted(catalog.keys())
+ [u'age', u'age2', u'message', u'message2', u'name', u'name2']
+
+Nuke the catalog and intids in the end, so as not to confuse
+other tests::
+
+ >>> sm = herd.getSiteManager()
+ >>> from zope.app.catalog.interfaces import ICatalog
+ >>> sm.unregisterUtility(catalog, provided=ICatalog)
+ True
+ >>> from zope.app.intid.interfaces import IIntIds
+ >>> from zope import component
+ >>> intids = component.getUtility(IIntIds)
+ >>> sm.unregisterUtility(intids, provided=IIntIds)
+ True
+
+Unfortunately ftests don't have good isolation from each other yet.
+"""
+
+from zope.interface import Interface
+from zope import schema
+
+import grok
+from grok import index
+
+class Herd(grok.Container, grok.Application):
+ pass
+
+class IMammoth(Interface):
+ name = schema.TextLine(title=u'Name')
+ age = schema.Int(title=u'Age')
+ def message():
+ """Message the mammoth has for the world."""
+
+class IMammoth2(Interface):
+ name2 = schema.TextLine(title=u'Name')
+ age2 = schema.Int(title=u'Age')
+ def message2():
+ """Message the mammoth has for the world."""
+
+class MammothIndexes(grok.Indexes):
+ grok.site(Herd)
+ grok.context(IMammoth)
+
+ name = index.Field()
+ age = index.Field()
+ message = index.Text()
+
+class MammothIndexes2(grok.Indexes):
+ grok.site(Herd)
+ grok.context(IMammoth2)
+
+ name2 = index.Field()
+ age2 = index.Field()
+ message2 = index.Text()
Modified: grok/branches/faassen-index/src/grok/meta.py
===================================================================
--- grok/branches/faassen-index/src/grok/meta.py 2007-04-20 14:32:04 UTC (rev 74261)
+++ grok/branches/faassen-index/src/grok/meta.py 2007-04-20 14:34:33 UTC (rev 74262)
@@ -533,7 +533,7 @@
If the catalog already exists, return that.
"""
catalog = zope.component.queryUtility(
- ICatalog, name=self.catalog_name, default=None)
+ ICatalog, name=self.catalog_name, context=site, default=None)
if catalog is not None:
return catalog
catalog = Catalog()
@@ -544,7 +544,7 @@
"""Create intids if needed, and return it.
"""
intids = zope.component.queryUtility(
- IIntIds, default=None)
+ IIntIds, context=site, default=None)
if intids is not None:
return intids
intids = IntIds()
More information about the Checkins
mailing list