[Checkins] SVN: grok/trunk/src/grok/ Pick up grok.Container as a model too. Do this instead of subclassing

Martijn Faassen faassen at infrae.com
Tue Oct 31 12:16:14 EST 2006


Log message for revision 71013:
  Pick up grok.Container as a model too. Do this instead of subclassing
  grok.Container from grok.Model. This works as well, but leads to MRO errors
  when for some reason combining grok.Container with grok.Model in base classes.
  This approach works too.
  

Changed:
  U   grok/trunk/src/grok/_grok.py
  U   grok/trunk/src/grok/tests/container/container.py
  A   grok/trunk/src/grok/tests/container/container_model.py

-=-
Modified: grok/trunk/src/grok/_grok.py
===================================================================
--- grok/trunk/src/grok/_grok.py	2006-10-31 16:49:46 UTC (rev 71012)
+++ grok/trunk/src/grok/_grok.py	2006-10-31 17:16:13 UTC (rev 71013)
@@ -114,8 +114,10 @@
 
 
 def scan_module(module_info):
+    models = []
     components = {
-            grok.Model: [],
+            grok.Model: models,
+            grok.Container: models,
             grok.Adapter: [],
             grok.MultiAdapter: [],
             grok.Utility: [],

Modified: grok/trunk/src/grok/tests/container/container.py
===================================================================
--- grok/trunk/src/grok/tests/container/container.py	2006-10-31 16:49:46 UTC (rev 71012)
+++ grok/trunk/src/grok/tests/container/container.py	2006-10-31 17:16:13 UTC (rev 71013)
@@ -1,6 +1,8 @@
 """
 
-The grok.Container is just a convenient subclass of the BTreeContainer that lives in the Zope 3 core:
+The grok.Container is a a model that is also a container.  It has a
+dictionary API. It in fact stores its information in a BTree so
+you can store a lot of items in a scalable way.
 
     >>> grok.grok(__name__)
 
@@ -12,7 +14,7 @@
     >>> from zope.app.container.btree import BTreeContainer
     >>> isinstance(bag, BTreeContainer)
     True
-
+     
 We had problems when switching to grok.Container with the __parent__ attribute
 being set, we better make sure this doesn't happen again:
 
@@ -31,8 +33,8 @@
 
 import grok
 
-class BoneBag(grok.Model, grok.Container):
+class BoneBag(grok.Container):
     pass
-
+    
 class Bone(grok.Model):
     pass

Added: grok/trunk/src/grok/tests/container/container_model.py
===================================================================
--- grok/trunk/src/grok/tests/container/container_model.py	2006-10-31 16:49:46 UTC (rev 71012)
+++ grok/trunk/src/grok/tests/container/container_model.py	2006-10-31 17:16:13 UTC (rev 71013)
@@ -0,0 +1,24 @@
+"""
+We make sure we indeed have a view for BoneBag; this way we know it's
+registered as the default context object:
+
+
+    >>> grok.grok(__name__)
+    >>> bag = BoneBag()
+    >>> from zope import component
+    >>> from zope.publisher.browser import TestRequest
+    >>> request = TestRequest()
+    >>> view = component.getMultiAdapter((bag, request), name='index')
+    >>> view()
+    'Hello world'
+"""
+import grok
+
+class BoneBag(grok.Container):
+    pass
+
+class Index(grok.View):
+    """A simple view to test whether BoneBag is really registered as a model.
+    """
+    def render(self):
+        return "Hello world"



More information about the Checkins mailing list