[Checkins] SVN: grok/branches/faassen-index/src/grok/ Make indexes work with sites, not only applications. This means grok.site

Martijn Faassen faassen at infrae.com
Fri Apr 20 09:24:44 EDT 2007


Log message for revision 74258:
  Make indexes work with sites, not only applications. This means grok.site
  can be used.
  

Changed:
  U   grok/branches/faassen-index/src/grok/__init__.py
  U   grok/branches/faassen-index/src/grok/components.py
  U   grok/branches/faassen-index/src/grok/directive.py
  U   grok/branches/faassen-index/src/grok/ftests/catalog/indexes.py
  U   grok/branches/faassen-index/src/grok/ftests/catalog/indexes_app_interface.py
  U   grok/branches/faassen-index/src/grok/ftests/catalog/indexes_class.py
  U   grok/branches/faassen-index/src/grok/ftests/catalog/indexes_name.py
  U   grok/branches/faassen-index/src/grok/ftests/catalog/indexes_no_app.py
  A   grok/branches/faassen-index/src/grok/ftests/catalog/indexes_site.py
  U   grok/branches/faassen-index/src/grok/meta.py

-=-
Modified: grok/branches/faassen-index/src/grok/__init__.py
===================================================================
--- grok/branches/faassen-index/src/grok/__init__.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/__init__.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -37,7 +37,7 @@
 from grok.components import Indexes
 from grok.directive import (context, name, template, templatedir, provides,
                             baseclass, global_utility, local_utility,
-                            define_permission, require, application)
+                            define_permission, require, site)
 from grok._grok import do_grok as grok  # Avoid name clash within _grok
 from grok._grok import SubscribeDecorator as subscribe
 from grok.error import GrokError, GrokImportError

Modified: grok/branches/faassen-index/src/grok/components.py
===================================================================
--- grok/branches/faassen-index/src/grok/components.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/components.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -454,7 +454,7 @@
             return
         # make sure we take over a bunch of possible attributes
         for name in ['__grok_context__', '__grok_name__',
-                     '__grok_application__']:
+                     '__grok_site__']:
             value = attrs.get(name)
             if value is not None:
                 setattr(self, name, value)

Modified: grok/branches/faassen-index/src/grok/directive.py
===================================================================
--- grok/branches/faassen-index/src/grok/directive.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/directive.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -277,6 +277,5 @@
 define_permission = MultipleTextDirective('grok.define_permission',
                                           ModuleDirectiveContext())
 require = RequireDirective('grok.require', ClassDirectiveContext())
-application = InterfaceOrClassDirective('grok.application',
-                                        ClassDirectiveContext())
-
+site = InterfaceOrClassDirective('grok.site',
+                                 ClassDirectiveContext())

Modified: grok/branches/faassen-index/src/grok/ftests/catalog/indexes.py
===================================================================
--- grok/branches/faassen-index/src/grok/ftests/catalog/indexes.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/ftests/catalog/indexes.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -85,7 +85,7 @@
         """Message the mammoth has for the world."""
 
 class MammothIndexes(grok.Indexes):
-    grok.application(Herd)
+    grok.site(Herd)
     grok.context(IMammoth)
 
     name = index.Field()

Modified: grok/branches/faassen-index/src/grok/ftests/catalog/indexes_app_interface.py
===================================================================
--- grok/branches/faassen-index/src/grok/ftests/catalog/indexes_app_interface.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/ftests/catalog/indexes_app_interface.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -81,7 +81,7 @@
         """Message the mammoth has for the world."""
 
 class MammothIndexes(grok.Indexes):
-    grok.application(IHerd)
+    grok.site(IHerd)
     grok.context(IMammoth)
 
     name = index.Field()

Modified: grok/branches/faassen-index/src/grok/ftests/catalog/indexes_class.py
===================================================================
--- grok/branches/faassen-index/src/grok/ftests/catalog/indexes_class.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/ftests/catalog/indexes_class.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -73,7 +73,7 @@
 
 class MammothIndexes(grok.Indexes):
     grok.context(Mammoth)
-    grok.application(Herd)
+    grok.site(Herd)
     
     name = index.Field()
     age = index.Field()

Modified: grok/branches/faassen-index/src/grok/ftests/catalog/indexes_name.py
===================================================================
--- grok/branches/faassen-index/src/grok/ftests/catalog/indexes_name.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/ftests/catalog/indexes_name.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -56,7 +56,7 @@
 class MammothIndexes(grok.Indexes):
     grok.context(Mammoth)
     grok.name('foo_catalog')
-    grok.application(Herd)
+    grok.site(Herd)
     
     name = index.Field()
     age = index.Field()

Modified: grok/branches/faassen-index/src/grok/ftests/catalog/indexes_no_app.py
===================================================================
--- grok/branches/faassen-index/src/grok/ftests/catalog/indexes_no_app.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/ftests/catalog/indexes_no_app.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -1,15 +1,15 @@
 """
 Grok allows you to set up catalog indexes in your application with a
-special indexes declaration.  We do need to specify an application for
-the Indexes however, otherwise we get a GrokError:
+special indexes declaration.  We do need to specify a site (such as
+the application) for the Indexes however, otherwise we get a GrokError:
 
   >>> import grok
   >>> grok.grok('grok.ftests.catalog.indexes_no_app')
   Traceback (most recent call last):
     ...
-  GrokError: No application specified for grok.Indexes subclass in module
+  GrokError: No site specified for grok.Indexes subclass in module
   <module 'grok.ftests.catalog.indexes_no_app' from ...>.
-  Use grok.application() to specify.
+  Use grok.site() to specify.
   
 """
 import grok

Added: grok/branches/faassen-index/src/grok/ftests/catalog/indexes_site.py
===================================================================
--- grok/branches/faassen-index/src/grok/ftests/catalog/indexes_site.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/ftests/catalog/indexes_site.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -0,0 +1,60 @@
+"""
+Grok allows you to set up catalog indexes in your application with a
+special indexes declaration. In fact, these indexes can be set up for
+any site::
+
+  >>> import grok
+  >>> grok.grok('grok.ftests.catalog.indexes_site')
+
+Let's set up a site in which we manage a couple of objects::
+
+  >>> from grok.ftests.catalog.indexes_site import Herd
+  >>> herd = Herd()
+  >>> getRootFolder()['herd'] = herd
+  >>> from zope.app.component.hooks import setSite
+  >>> setSite(herd)
+
+The catalog is there in the site::
+
+  >>> from zope.app.catalog.interfaces import ICatalog
+  >>> from zope.component import getUtility, queryUtility
+  >>> catalog = queryUtility(ICatalog, default=None)
+  >>> catalog is not None
+  True
+
+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
+"""
+
+from zope.interface import Interface
+from zope import schema
+
+import grok
+from grok import index
+
+class Herd(grok.Container, grok.Site):
+    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 MammothIndexes(grok.Indexes):
+    grok.site(Herd)
+    grok.context(IMammoth)
+
+    name = index.Field()
+    age = index.Field()
+    message = index.Text()

Modified: grok/branches/faassen-index/src/grok/meta.py
===================================================================
--- grok/branches/faassen-index/src/grok/meta.py	2007-04-20 09:55:10 UTC (rev 74257)
+++ grok/branches/faassen-index/src/grok/meta.py	2007-04-20 13:24:43 UTC (rev 74258)
@@ -496,11 +496,11 @@
     component_class = components.IndexesClass
 
     def register(self, context, name, factory, module_info, templates):
-        application = util.class_annotation(factory, 'grok.application', None)
-        if application is None:
-            raise GrokError("No application specified for grok.Indexes "
+        site = util.class_annotation(factory, 'grok.site', None)
+        if site is None:
+            raise GrokError("No site specified for grok.Indexes "
                             "subclass in module %r. "
-                            "Use grok.application() to specify." % module_info.getModule(),
+                            "Use grok.site() to specify." % module_info.getModule(),
                             factory)
         indexes = util.class_annotation(factory, 'grok.indexes', None)
         if indexes is None:
@@ -509,7 +509,7 @@
         catalog_name = util.class_annotation(factory, 'grok.name', u'')
         zope.component.provideHandler(
             IndexesSetupSubscriber(catalog_name, indexes, context),
-            adapts=(application,
+            adapts=(site,
                     grok.IObjectAddedEvent))
         
 class IndexesSetupSubscriber(object):
@@ -518,16 +518,16 @@
         self.indexes = indexes
         self.context = context
         
-    def __call__(self, app, event):
+    def __call__(self, site, event):
         # make sure we have an intids
-        self._createIntIds(app)
+        self._createIntIds(site)
         # get the catalog
-        catalog = self._createCatalog(app)
+        catalog = self._createCatalog(site)
         # now install indexes
         for name, index in self.indexes.items():
             index.setup(catalog, name, self.context)
 
-    def _createCatalog(self, app):
+    def _createCatalog(self, site):
         """Create the catalog if needed and return it.
 
         If the catalog already exists, return that.
@@ -537,10 +537,10 @@
         if catalog is not None:
             return catalog
         catalog = Catalog()
-        setupUtility(app, catalog, ICatalog, name=self.catalog_name)
+        setupUtility(site, catalog, ICatalog, name=self.catalog_name)
         return catalog
     
-    def _createIntIds(self, app):
+    def _createIntIds(self, site):
         """Create intids if needed, and return it.
         """
         intids = zope.component.queryUtility(
@@ -548,5 +548,5 @@
         if intids is not None:
             return intids
         intids = IntIds()
-        setupUtility(app, intids, IIntIds)
+        setupUtility(site, intids, IIntIds)
         return intids



More information about the Checkins mailing list