[Checkins] SVN: grok/branches/faassen-index/src/grok/ grok.name works to set the name of the catalog.

Martijn Faassen faassen at infrae.com
Tue Apr 17 16:48:28 EDT 2007


Log message for revision 74217:
  grok.name works to set the name of the catalog.

Changed:
  U   grok/branches/faassen-index/src/grok/components.py
  A   grok/branches/faassen-index/src/grok/ftests/catalog/indexes_name.py

-=-
Modified: grok/branches/faassen-index/src/grok/components.py
===================================================================
--- grok/branches/faassen-index/src/grok/components.py	2007-04-17 20:28:17 UTC (rev 74216)
+++ grok/branches/faassen-index/src/grok/components.py	2007-04-17 20:48:27 UTC (rev 74217)
@@ -456,6 +456,10 @@
         context = attrs.get('__grok_context__')
         if context is not None:
             self.__grok_context__ = context
+        # and __grok_name__
+        name = attrs.get('__grok_name__')
+        if name is not None:
+            self.__grok_name__ = name
             
         indexes = {}
         for name, value in attrs.items():

Added: grok/branches/faassen-index/src/grok/ftests/catalog/indexes_name.py
===================================================================
--- grok/branches/faassen-index/src/grok/ftests/catalog/indexes_name.py	2007-04-17 20:28:17 UTC (rev 74216)
+++ grok/branches/faassen-index/src/grok/ftests/catalog/indexes_name.py	2007-04-17 20:48:27 UTC (rev 74217)
@@ -0,0 +1,62 @@
+"""
+Grok allows you to set up catalog indexes in your application with a
+special indexes declaration. We can specify the catalog name using
+grok.name.
+
+  >>> import grok
+  >>> grok.grok('grok.ftests.catalog.indexes_name')
+
+Let's set up a site in which we manage a couple of objects::
+
+  >>> from grok.ftests.catalog.indexes import Herd, Mammoth
+  >>> herd = Herd()
+  >>> getRootFolder()['herd'] = herd
+  >>> from zope.app.component.hooks import setSite
+  >>> setSite(herd)
+
+  >>> from zope.app.catalog.interfaces import ICatalog
+  >>> from zope.component import getUtility
+
+We have to look up the catalog by name now::
+
+  >>> catalog = getUtility(ICatalog, 'foo_catalog')
+  >>> catalog
+  <zope.app.catalog.catalog.Catalog object at ...>
+
+Nuke the catalog and initds 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, name='foo_catalog')
+  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.
+"""
+import grok
+from grok import index
+
+class Mammoth(grok.Model):
+    def __init__(self, name, age, message):
+        self.name = name
+        self.age = age
+        self._message = message
+
+    def message(self):
+        return self._message
+
+class MammothIndexes(grok.Indexes):
+    grok.context(Mammoth)
+    grok.name('foo_catalog')
+    
+    name = index.Field()
+    age = index.Field()
+    message = index.Text()
+
+class Herd(grok.Container, grok.Application):
+    pass



More information about the Checkins mailing list