[Checkins] SVN: z3c.jbot/trunk/z3c/jbot/ Also patch the Zope 2 page template file class; this fix makes sure that templates are only compiled once per source.

Malthe Borch mborch at gmail.com
Tue Jul 15 05:08:53 EDT 2008


Log message for revision 88375:
  Also patch the Zope 2 page template file class; this fix makes sure that templates are only compiled once per source.

Changed:
  U   z3c.jbot/trunk/z3c/jbot/Five.txt
  U   z3c.jbot/trunk/z3c/jbot/__init__.py

-=-
Modified: z3c.jbot/trunk/z3c/jbot/Five.txt
===================================================================
--- z3c.jbot/trunk/z3c/jbot/Five.txt	2008-07-15 02:46:23 UTC (rev 88374)
+++ z3c.jbot/trunk/z3c/jbot/Five.txt	2008-07-15 09:08:51 UTC (rev 88375)
@@ -77,3 +77,25 @@
   
   >>> z3c.jbot.utility.getManager() is manager
   True
+
+Verify that template attributes are set per request layer.
+
+  >>> view.template._v_last_read is not False
+  True
+
+  >>> class ISpecificLayer(interface.Interface):
+  ...     pass
+
+  >>> interface.alsoProvides(MockSite.REQUEST, ISpecificLayer)
+  >>> view.template._v_last_read = False
+  >>> view.template._v_last_read is False
+  True
+
+No longer providing this layer, we expect an attribute lookup to
+return the value that was set before the layer was provided.
+  
+  >>> interface.noLongerProvides(MockSite.REQUEST, ISpecificLayer)
+  >>> view.template._v_last_read is not False
+  True  
+  
+

Modified: z3c.jbot/trunk/z3c/jbot/__init__.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/__init__.py	2008-07-15 02:46:23 UTC (rev 88374)
+++ z3c.jbot/trunk/z3c/jbot/__init__.py	2008-07-15 09:08:51 UTC (rev 88375)
@@ -4,7 +4,12 @@
 import utility
 
 NO_DEFAULT = object()
+PT_CLASSES = [PageTemplateFile]
 
+if utility.ZOPE_2:
+    from Products.PageTemplates.PageTemplateFile import PageTemplateFile as Z2PageTemplateFile
+    PT_CLASSES.append(Z2PageTemplateFile)
+
 class LayerProperty(property):
     """Layer-specific property class.
 
@@ -42,15 +47,11 @@
         return func(self, *args, **kwargs)        
     return patch
 
-# patch ``_cook_check``-method to insert jbot-logic
-PageTemplateFile._cook_check = jbot(PageTemplateFile._cook_check)
-try:
-    from Products.PageTemplates.PageTemplateFile import PageTemplateFile as Z2PageTemplateFile
-    Z2PageTemplateFile._cook_check = jbot(Z2PageTemplateFile._cook_check)
-except ImportError:
-    pass
+for pt_class in PT_CLASSES:
+    # patch ``_cook_check``-method to insert jbot-logic
+    pt_class._cook_check = jbot(pt_class._cook_check)
 
-# munge per-layer attribute descriptors on class
-for name in ('_v_macros', '_v_program', '_v_cooked', '_v_errors',
-             '_v_last_read', '_v_warning', '_text_', 'filename'):
-    setattr(PageTemplateFile, name, LayerProperty(name))
+    # munge per-layer attribute descriptors on class
+    for name in ('_v_macros', '_v_program', '_v_cooked', '_v_errors',
+                 '_v_last_read', '_v_warning', '_text_', 'filename'):
+        setattr(pt_class, name, LayerProperty(name))



More information about the Checkins mailing list