[Checkins] SVN: five.pt/trunk/src/five/pt/patches.py Better hack for Chameleon integration into five.grok views

Vincent Fretin vincent.fretin at gmail.com
Wed Apr 14 14:00:35 EDT 2010


Log message for revision 110910:
  Better hack for Chameleon integration into five.grok views

Changed:
  U   five.pt/trunk/src/five/pt/patches.py

-=-
Modified: five.pt/trunk/src/five/pt/patches.py
===================================================================
--- five.pt/trunk/src/five/pt/patches.py	2010-04-14 17:53:42 UTC (rev 110909)
+++ five.pt/trunk/src/five/pt/patches.py	2010-04-14 18:00:35 UTC (rev 110910)
@@ -85,19 +85,27 @@
 try:
     from five.grok.components import ZopeTwoPageTemplate
 
-    _tpf  = FiveViewPageTemplateFile(__file__)
     class GrokViewAwarePageTemplateFile(ViewPageTemplateFile):
-        def pt_getContext(self, *args, **kw):
-            global _tpf
-            return _tpf.pt_getContext(*args, **kw)
-        def pt_render(self, namespace, **kw):
-            if "args" in namespace:
-                del namespace["args"]
-            context=namespace.pop("context")
-            request=namespace.pop("request")
-            view=namespace["view"]
-            return self.__call__(_ob=view, context=context, request=request, **namespace)
 
+        def pt_getContext(self, instance, request, **kw):
+            return {}
+    
+        def _pt_get_context(self, instance, request, kwargs={}):
+            namespace = super(GrokViewAwarePageTemplateFile, self)._pt_get_context(
+                instance, request, kwargs)
+            if hasattr(self, 'pt_grokContext'):
+                namespace.update(self.pt_grokContext)
+            return namespace
+
+        def pt_render(self, namespace):
+            self.pt_grokContext = namespace
+            # namespace contains self.pt_getContext() result + \
+            # five.grok.components.ZopeTwoPageTemplate.getNamespace(view) result
+            # we have currently context, request, static, and view in the dict
+            view = namespace["view"]
+            return self.__call__(_ob=view)
+            # z3c.pt.pagetemplate.ViewPageTemplate.__call__ will call self._pt_get_context(ob, None, None)
+
     def setFromFilename(self, filename, _prefix=None):
         self._template = GrokViewAwarePageTemplateFile(filename, _prefix)
     ZopeTwoPageTemplate.setFromFilename = setFromFilename



More information about the checkins mailing list