[Checkins] SVN: grok/trunk/src/grok/ Local utilities defined in base classes will be installed before

Philipp von Weitershausen philikon at philikon.de
Sun Jan 7 12:49:04 EST 2007


Log message for revision 71782:
  Local utilities defined in base classes will be installed before
  those in subclasses.
  

Changed:
  A   grok/trunk/src/grok/ftests/catalog/setuporder.py
  U   grok/trunk/src/grok/tests/util/class_annotation.py
  U   grok/trunk/src/grok/util.py

-=-
Added: grok/trunk/src/grok/ftests/catalog/setuporder.py
===================================================================
--- grok/trunk/src/grok/ftests/catalog/setuporder.py	2007-01-07 17:41:52 UTC (rev 71781)
+++ grok/trunk/src/grok/ftests/catalog/setuporder.py	2007-01-07 17:49:03 UTC (rev 71782)
@@ -0,0 +1,57 @@
+"""
+This is similar to catalog.py, except that the site uses a base class
+which also defines a local utility.
+
+  >>> import grok
+  >>> from grok.ftests.catalog.setuporder import Mammoth, Herd
+  >>> grok.grok('grok.ftests.catalog.setuporder')
+
+Let's setup a site in which we manage a couple of objects:
+
+  >>> herd = Herd()
+  >>> getRootFolder()['herd'] = herd
+  >>> from zope.app.component.hooks import setSite
+  >>> setSite(herd)
+
+Now we add some indexable objects to the site:
+
+  >>> herd['manfred'] = Mammoth('Manfred')
+  >>> herd['ellie'] = Mammoth('Ellie')
+
+Then we are able to query the catalog:
+
+  >>> from zope.app.catalog.interfaces import ICatalog
+  >>> from zope.component import getUtility
+  >>> catalog = getUtility(ICatalog)
+  >>> for obj in catalog.searchResults(name=('Ellie', 'Ellie')):
+  ...     print obj.name
+  Ellie
+
+"""
+
+import grok
+from zope import schema, interface
+from zope.app.intid import IntIds
+from zope.app.intid.interfaces import IIntIds
+from zope.app.catalog.catalog import Catalog
+from zope.app.catalog.interfaces import ICatalog
+from zope.app.catalog.field import FieldIndex
+
+def setup_catalog(catalog):
+    catalog['name'] = FieldIndex('name', IMammoth)
+
+class IMammoth(interface.Interface):
+
+    name = schema.TextLine()
+
+class Mammoth(grok.Model):
+    grok.implements(IMammoth)
+
+    def __init__(self, name):
+        self.name = name
+
+class BaseHerd(grok.Container, grok.Site):
+    grok.local_utility(IntIds, provides=IIntIds)
+
+class Herd(BaseHerd):
+    grok.local_utility(Catalog, provides=ICatalog, setup=setup_catalog)


Property changes on: grok/trunk/src/grok/ftests/catalog/setuporder.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: grok/trunk/src/grok/tests/util/class_annotation.py
===================================================================
--- grok/trunk/src/grok/tests/util/class_annotation.py	2007-01-07 17:41:52 UTC (rev 71781)
+++ grok/trunk/src/grok/tests/util/class_annotation.py	2007-01-07 17:49:03 UTC (rev 71782)
@@ -1,13 +1,13 @@
 """
   >>> util.class_annotation_list(B, 'grok.foo', None)
-  [7, 5]
+  [5, 7]
   >>> util.class_annotation_list(B2, 'grok.foo', None)
   [5]
   >>> util.class_annotation_list(C, 'grok.foo', None)
-  [8, 7, 5]
+  [5, 7, 8]
   >>> util.class_annotation_list(C2, 'grok.foo', None)
-  [9, 5, 7]
-  
+  [5, 7, 9]
+
 """
 import grok
 from grok import util

Modified: grok/trunk/src/grok/util.py
===================================================================
--- grok/trunk/src/grok/util.py	2007-01-07 17:41:52 UTC (rev 71781)
+++ grok/trunk/src/grok/util.py	2007-01-07 17:49:03 UTC (rev 71782)
@@ -61,7 +61,7 @@
         return default
 
     result = []
-    for base in obj.mro():
+    for base in reversed(obj.mro()):
         list = class_annotation(base, name, [])
         if list not in result:
             result.append(list)



More information about the Checkins mailing list