[Checkins] SVN: five.pt/trunk/ Fixed issue where template would not be installed with a viewlet manager, even if the parameter is provided.

Malthe Borch mborch at gmail.com
Fri Feb 13 11:55:32 EST 2009


Log message for revision 96496:
  Fixed issue where template would not be installed with a viewlet manager, even if the parameter is provided.

Changed:
  U   five.pt/trunk/CHANGES.txt
  U   five.pt/trunk/src/five/pt/zcml.py

-=-
Modified: five.pt/trunk/CHANGES.txt
===================================================================
--- five.pt/trunk/CHANGES.txt	2009-02-13 16:53:33 UTC (rev 96495)
+++ five.pt/trunk/CHANGES.txt	2009-02-13 16:55:32 UTC (rev 96496)
@@ -3,6 +3,9 @@
 
 In next version
 
+- Fixed issue where the ``template`` parameter to a viewlet manager
+  directive was effectively ignored. [malthe]
+
 - Fixed acquisition-wrapping issue with the (patched) bound template
   class (could cause infinite loop due to cyclic acquisition
   chain). [malthe]

Modified: five.pt/trunk/src/five/pt/zcml.py
===================================================================
--- five.pt/trunk/src/five/pt/zcml.py	2009-02-13 16:53:33 UTC (rev 96495)
+++ five.pt/trunk/src/five/pt/zcml.py	2009-02-13 16:55:32 UTC (rev 96496)
@@ -1,6 +1,8 @@
 import sys
 
 from zope.interface import classImplements
+from zope.configuration.config import ConfigurationMachine
+from zope.component import zcml
 from zope.viewlet.interfaces import IViewletManager
 
 from Products.Five.viewlet import viewlet
@@ -43,7 +45,7 @@
 
     return class_
 
-def ViewletManager(name, interface, template=None, bases=()):
+def ViewletManager2(name, interface, template=None, bases=()):
     attrs = {'__name__' : name}
     if template is not None:
         attrs['template'] = ViewPageTemplateFile(template)
@@ -83,14 +85,30 @@
     return viewletmeta.viewletDirective(_context, name, *args, **kwargs)
 
 def viewlet_manager_directive(_context, name, *args, **kwargs):
+    template = kwargs.pop('template', None)
+    provides = kwargs.setdefault('provides', IViewletManager)
     class_ = kwargs.get('class_')
-    template = kwargs.get('template')
-    provides = kwargs.setdefault('provides', IViewletManager)
+    
+    if template is None:
+        return viewletmeta.viewletManagerDirective(
+            _context, name, *args, **kwargs)
 
-    if template:
-        bases = class_ and (class_,) or ()
-        kwargs['class_'] = ViewletManager(
-            name, provides, template=str(template), bases=bases)
-        del kwargs['template']
-        
-    return viewletmeta.viewletManagerDirective(_context, name, *args, **kwargs)
+    _new = ConfigurationMachine()
+    viewletmeta.viewletManagerDirective(_new, name, *args, **kwargs)
+    
+    for action in _new.actions:
+        try:
+            discriminator, handler, args = action
+            try:
+                name = discriminator.__getitem__(0)
+            except (AttributeError, IndexError):
+                continue
+
+            if name == 'viewletManager':
+                assert handler is zcml.handler, \
+                       "Unsupported action handler '%s'." % repr(handler)
+                new_class = args[1]
+                new_class.template = ViewPageTemplateFile(template)
+        finally:
+            _context.actions.append(action)
+            



More information about the Checkins mailing list