[Zope3-checkins] SVN: Zope3/branches/roger-contentprovider/src/zope/viewlet/ Work in progress: viewlet and viewletManager directives are on its way

Helmut Merz helmutm at cy55.de
Mon Oct 10 15:50:34 EDT 2005


Log message for revision 39036:
  Work in progress: viewlet and viewletManager directives are on its way

Changed:
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/directives.txt
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/manager.py
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py

-=-
Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/directives.txt
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/directives.txt	2005-10-10 18:58:15 UTC (rev 39035)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/directives.txt	2005-10-10 19:50:34 UTC (rev 39036)
@@ -1,11 +1,14 @@
-=========================
-The ``viewlet`` Directive
-=========================
+=================================================
+The ``viewletManager`` and ``viewlet`` Directives
+=================================================
 
 The viewlet directive allows you to quickly register a new paglet without much
 hassle, like it was shown in the `README.txt` file. Here is a sample
 directive::
 
+  >>> from zope.app import zapi
+  >>> import zope.interface
+  
   >>> from zope.viewlet.tests import ILeftViewlet
   >>> from zope.configuration import xmlconfig
   >>> context = xmlconfig.string('''
@@ -16,6 +19,14 @@
 
   >>> import os, tempfile
   >>> temp_dir = tempfile.mkdtemp()
+
+  >>> testViewletManager = os.path.join(temp_dir, 'testviewletmanager.pt')
+  >>> open(testViewletManager, 'w').write('''
+  ... <div tal:repeat="viewlet options/viewlets"
+  ...   <div tal:replace="viewlet"></div>
+  ... </div>
+  ... ''')
+
   >>> testViewlet = os.path.join(temp_dir, 'testviewlet.pt')
   >>> open(testViewlet, 'w').write('''
   ... <div>testviewlet content</div>
@@ -24,6 +35,13 @@
   >>> context = xmlconfig.string('''
   ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
   ...            package="zope.viewlet.tests">
+  ...   <viewletManager
+  ...       name="testviewlet"
+  ...       for="*"
+  ...       providerType="zope.viewlet.tests.ILeftViewlet"
+  ...       template="%s"
+  ...       permission="zope.Public"
+  ...       />
   ...   <viewlet
   ...       name="testviewlet"
   ...       for="*"
@@ -32,7 +50,7 @@
   ...       permission="zope.Public"
   ...       />
   ... </configure>
-  ... ''' % testViewlet, context=context)
+  ... ''' % (testViewletManager, testViewlet), context=context)
 
 As you can see, the directive looks very similar to the page directive and you
 are right. The viewlet directive does not permit you to specify a `menu` and
@@ -46,7 +64,7 @@
 If we now look into the adapter registry, we will find the viewlet:
 
   >>> class Content(object):
-  ...     pass
+  ...     zope.interface.implements(zope.interface.Interface)
   >>> content = Content()
 
   >>> from zope.publisher.browser import TestRequest
@@ -56,11 +74,12 @@
   >>> view = BrowserView(content, request)
 
   >>> import zope.interface
-  >>> from zope.viewlet.interfaces import IViewlet
+  >>> from zope.viewlet.interfaces import IViewlet, IViewletManager
   
-  >>> import zope.component
-  >>> viewlet = zope.component.getMultiAdapter(
-  ...     (content, request, view), ILeftViewlet, name='testviewlet')
+  >>> manager = zapi.getMultiAdapter(
+  ...     (content, request, view), IViewletManager, name='testviewlet')
+  >>> viewlet = zapi.getMultiAdapter(
+  ...     (content, request, view, manager), IViewlet, name='testviewlet')
   >>> viewlet().strip()
   u'<div>testviewlet content</div>'
 
@@ -81,7 +100,7 @@
   ... ''' % testViewlet, context=context)
 
   >>> viewlet = zope.component.getMultiAdapter(
-  ...     (content, request, view), ILeftViewlet, name='testviewlet2')
+  ...     (content, request, view, manager), name='testviewlet2')
   >>> viewlet().strip()
   u'<div>testviewlet content</div>'
 

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/manager.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/manager.py	2005-10-10 18:58:15 UTC (rev 39035)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/manager.py	2005-10-10 19:50:34 UTC (rev 39036)
@@ -111,9 +111,12 @@
     if template is not None:
         template = ViewPageTemplateFile(template)
 
+    if ViewletManagerBase not in bases:
+        bases = bases + (ViewletManagerBase,)
+
     ViewletManager = type(
         '<ViewletManager providing %s>' % interface.getName(),
-        bases+(ViewletManagerBase,),
+        bases,
         {'template': template})
     zope.interface.classImplements(ViewletManager, interface)
     return ViewletManager

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py	2005-10-10 18:58:15 UTC (rev 39035)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py	2005-10-10 19:50:34 UTC (rev 39036)
@@ -52,7 +52,7 @@
 
     # If class is not given we use the default viewlet manager.
     if class_ is None:
-        class_ = manager.ViewletManager
+        class_ = manager.ViewletManagerBase
 
     # Make sure that the template exists and that all low-level API methods
     # have the right permission.
@@ -63,8 +63,8 @@
         required['__getitem__'] = permission
 
         # Create a new class based on the template and class.
-        new_class = viewlet.SimpleViewletClass(
-            template, bases=(class_, ))
+        new_class = manager.ViewletManager(
+            providerType, bases=(class_, ))
 
     if hasattr(new_class, '__implements__'):
         classImplements(new_class, IBrowserPublisher)
@@ -74,7 +74,7 @@
         classImplements(new_class, providerType)
 
     for attr_name in ('browserDefault', '__call__',
-                      'publishTraverse', 'weight'):
+                      'publishTraverse'):
         required[attr_name] = permission
 
     viewmeta._handle_allowed_interface(
@@ -188,8 +188,8 @@
 
     # register viewlet
     _context.action(
-        discriminator = ('viewlet', for_, layer, view, name),
+        discriminator = ('viewlet', for_, layer, view, name, providerType),
         callable = metaconfigure.handler,
         args = ('provideAdapter',
-                (for_, layer, view), providerType, name, new_class,
-                 _context.info),)
+                (for_, layer, view, providerType), interfaces.IViewlet,
+                 name, new_class, _context.info),)

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py	2005-10-10 18:58:15 UTC (rev 39035)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py	2005-10-10 19:50:34 UTC (rev 39036)
@@ -46,7 +46,7 @@
 
     _weight = 0
 
-    def __init__(self, context, request, view):
+    def __init__(self, context, request, view, providerType):
         super(SimpleViewlet, self).__init__(context, request)
         self.view = view
 



More information about the Zope3-Checkins mailing list