[Zope3-checkins] SVN: Zope3/branches/roger-contentprovider/src/zope/contentprovider/ intermediate state for cleanup of manager.py

Helmut Merz helmutm at cy55.de
Thu Oct 6 16:05:01 EDT 2005


Log message for revision 38824:
  intermediate state for cleanup of manager.py

Changed:
  U   Zope3/branches/roger-contentprovider/src/zope/contentprovider/README.txt
  U   Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py
  U   Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/test_doc.py

-=-
Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/README.txt
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/README.txt	2005-10-06 19:33:55 UTC (rev 38823)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/README.txt	2005-10-06 20:05:00 UTC (rev 38824)
@@ -398,21 +398,21 @@
   </html>
 
 
-Viewlet Managers
-----------------
+Content Provider Managers
+-------------------------
 
 Until now we have always asserted that the viewlets returned by the TALES
-namespaces ``viewlets`` and ``viewlet`` always find the viewlets in the
+namespaces ``providers`` and ``provider`` always find the viewlets in the
 component architecture and then return them ordered by weight. This, however,
 is just the default policy. We could also register an alternative policy that
 has different rules on looking up, filtering and sorting the viewlets. The
 objects that implement those policies are known as viewlet managers.
 
-Viewlet managers are usually implemented as adapters from the context, request
-and view to the ``IViewletManager`` interface. They must implement two
-methods. The first one is ``getViewlets(region)``, which returns a list of
-viewlets for the specified region. The region argument is the region
-interface. The second method is ``getViewlet(name, region)``, which allows you
+Content provider managers are usually implemented as adapters from the context,
+request, view and region to the ``IContentProviderManager`` interface. They
+must implement two methods. The first one is ``values()``, which returns a list
+of viewlets for the specified region. The region argument is the region
+interface. The second method is ``__getitem__(name)``, which allows you
 to look up a specific viewlet by name and region.
 
 
@@ -424,11 +424,11 @@
 
   >>> from zope.contentprovider import manager
   >>> defaultManager = manager.DefaultContentProviderManager(
-  ...     content, request, FrontPage(content, request))
+  ...     content, request, FrontPage(content, request), ILeftColumn)
 
 we can now get a list of viewlets:
 
-  >>> defaultManager.values(ILeftColumn)
+  >>> defaultManager.values()
   [<InfoViewlet object at ...>,
    <Viewlet object at ...>]
 
@@ -450,14 +450,14 @@
   ...     ILeftColumn,
   ...     name='unauthorized')
 
-  >>> len(defaultManager.values(ILeftColumn))
+  >>> len(defaultManager.values())
   2
 
 Also, when you try to look up the unauthorized viewlet by name you will get an
 exception telling you that you have insufficient priviledges to access the
 viewlet:
 
-  >>> defaultManager.__getitem__('unauthorized', ILeftColumn)
+  >>> defaultManager.__getitem__('unauthorized')
   Traceback (most recent call last):
   ...
   Unauthorized: You are not authorized to access the viewlet
@@ -466,7 +466,7 @@
 When looking for a particular viewlet, you also get an exception, if none is
 found:
 
-  >>> defaultManager.__getitem__('unknown', ILeftColumn)
+  >>> defaultManager.__getitem__('unknown')
   Traceback (most recent call last):
   ...
   ComponentLookupError: 'No viewlet with name `unknown` found.'
@@ -487,9 +487,9 @@
 
   >>> class ContentsContentProviderManager(manager.DefaultContentProviderManager):
   ...
-  ...     def values(self, region):
+  ...     def values(self):
   ...         viewlets = zope.component.getAdapters(
-  ...             (self.context, self.request, self.view), region)
+  ...             (self.context, self.request, self.view), self.region)
   ...         viewlets = [(name, viewlet) for name, viewlet in viewlets
   ...                     if name in showColumns]
   ...         viewlets.sort(lambda x, y: cmp(showColumns.index(x[0]),
@@ -500,7 +500,7 @@
 
   >>> zope.component.provideAdapter(
   ...     ContentsContentProviderManager,
-  ...     (zope.interface.Interface, IDefaultBrowserLayer, IBrowserView),
+  ...     (zope.interface.Interface, IDefaultBrowserLayer, IBrowserView, ILeftColumn),
   ...     interfaces.IContentProviderManager)
 
   >>> view = zope.component.getMultiAdapter(
@@ -547,7 +547,7 @@
 
 On the other hand, it is as easy to remove a column:
 
-  >>> showColumns = ['name']
+  >>> showColumns = ['name', 'size']
   >>> print view().strip()
   <html>
     <body>

Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py	2005-10-06 19:33:55 UTC (rev 38823)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py	2005-10-06 20:05:00 UTC (rev 38824)
@@ -33,16 +33,17 @@
     """
     zope.interface.implements(interfaces.IContentProviderManager)
 
-    def __init__(self, context, request, view, region=None):
+    def __init__(self, context, request, view, region):
         self.context = context
         self.request = request
         self.view = view
         self.region = region
 
 
-    def values(self, region):
+    def values(self):
         """See zope.app.viewlet.interfaces.IViewletManager"""
         # Find all viewlets for this region
+        region = self.region
         viewlets = zope.component.getAdapters(
             (self.context, self.request, self.view), region)
         # Sort out all viewlets that cannot be accessed by the principal
@@ -54,9 +55,10 @@
         return viewlets
 
 
-    def __getitem__(self, name, region):
+    def __getitem__(self, name):
         """See zope.app.viewlet.interfaces.IViewletManager"""
         # Find the viewlet
+        region = self.region
         viewlet = zope.component.queryMultiAdapter(
             (self.context, self.request, self.view), region, name=name)
 

Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/test_doc.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/test_doc.py	2005-10-06 19:33:55 UTC (rev 38823)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/test_doc.py	2005-10-06 20:05:00 UTC (rev 38824)
@@ -27,7 +27,6 @@
 from zope.contentprovider import interfaces
 
 
-
 class TestParticipation(object):
     principal = 'foobar'
     interaction = None



More information about the Zope3-Checkins mailing list