[Checkins] SVN: megrok.chameleon/trunk/ Grok's idea of view template namespaces is put into the 'options' namespace by z3c.pt. This means namespaces like 'viewlet' and 'viewletmanager', but also whatever namespace was set by the view component's namespace() method would not be directly available in the template. This is fixed by updating the template context with Grok's idea of template namespaces. Added a test to demonstrate the issue.

Jan-Wijbrand Kolman janwijbrand at gmail.com
Thu Apr 14 06:54:50 EDT 2011


Log message for revision 121428:
  Grok's idea of view template namespaces is put into the 'options' namespace by z3c.pt. This means namespaces like 'viewlet' and 'viewletmanager', but also whatever namespace was set by the view component's namespace() method would not be directly available in the template. This is fixed by updating the template context with Grok's idea of template namespaces. Added a test to demonstrate the issue.

Changed:
  U   megrok.chameleon/trunk/buildout.cfg
  U   megrok.chameleon/trunk/src/megrok/chameleon/README.txt
  U   megrok.chameleon/trunk/src/megrok/chameleon/components.py
  U   megrok.chameleon/trunk/src/megrok/chameleon/tests/cpt_fixture/app.py

-=-
Modified: megrok.chameleon/trunk/buildout.cfg
===================================================================
--- megrok.chameleon/trunk/buildout.cfg	2011-04-14 06:52:07 UTC (rev 121427)
+++ megrok.chameleon/trunk/buildout.cfg	2011-04-14 10:54:49 UTC (rev 121428)
@@ -1,15 +1,12 @@
 [buildout]
 develop = .
 parts = interpreter test
-#extends = http://grok.zope.org/releaseinfo/grok-1.0.cfg
 extends = http://svn.zope.org/repos/main/groktoolkit/trunk/grok.cfg
 versions = versions
-#newest = false
-
 extensions = buildout.dumppickedversions
 
 [versions]
-Chameleon = 2.0-rc7
+Chameleon = 2.0-rc8
 ordereddict = 1.1
 unittest2 = 0.5.1
 z3c.pt = 2.0-rc1

Modified: megrok.chameleon/trunk/src/megrok/chameleon/README.txt
===================================================================
--- megrok.chameleon/trunk/src/megrok/chameleon/README.txt	2011-04-14 06:52:07 UTC (rev 121427)
+++ megrok.chameleon/trunk/src/megrok/chameleon/README.txt	2011-04-14 10:54:49 UTC (rev 121428)
@@ -216,7 +216,20 @@
     </body>
     </html>
 
+Custom template namespace names are supported:
 
+    >>> view = getMultiAdapter((manfred, request), name='namespace')
+    >>> print view()
+    <html>
+    <body>
+    This template knows about the following custom namespace name:
+    <BLANKLINE>
+      myname:
+       Henk
+    <BLANKLINE>
+    </body>
+    </html>
+
 Inline Templates
 ----------------
 
@@ -260,7 +273,7 @@
 * ``not``
      Evaluate the trailing expression to a boolean value and invert it.
 
-* ``path`` 
+* ``path``
      Handle the trailing expression as a path and not as a
      Python expression.
 

Modified: megrok.chameleon/trunk/src/megrok/chameleon/components.py
===================================================================
--- megrok.chameleon/trunk/src/megrok/chameleon/components.py	2011-04-14 06:52:07 UTC (rev 121427)
+++ megrok.chameleon/trunk/src/megrok/chameleon/components.py	2011-04-14 10:54:49 UTC (rev 121428)
@@ -28,7 +28,6 @@
     implementation in two respects:
 
     - It sets ``python`` as default mode (instead of ``path``)
-   
     - It injects any views ``static`` variable in template namespace.
     """
     default_expression = 'python' # Use the chameleon default
@@ -40,7 +39,7 @@
         """
         context = super(PageTemplate, self)._pt_get_context(
             view, request, kwargs)
-        context.update(dict(static = getattr(view, 'static', None)))
+        context.update(kwargs)
         return context
 
 class PageTemplateFile(PageTemplate, ViewPageTemplateFile):
@@ -50,13 +49,10 @@
     two respects:
 
     - It sets ``python`` as default mode (instead of ``path``)
-   
     - It injects any views ``static`` variable in template namespace.
     """
     default_expression = 'python'
 
-
-    
 class ChameleonPageTemplate(GrokTemplate):
 
     def setFromString(self, string):
@@ -69,20 +65,6 @@
         self._template = PageTemplateFile(os.path.join(_prefix, filename))
         return
 
-    def getNamespace(self, view):
-        """Extend namespace.
-
-        Beside the vars defined in standard grok templates, we inject
-        some vars and functions to be more compatible with official
-        ZPTs.
-        """
-        namespace = super(ChameleonPageTemplate, self).getNamespace(view)
-        namespace.update(dict(
-                template=self,
-                _ob=view, # z3c.pt expects this strange key for the view
-                ))
-        return namespace
-
     @property
     def macros(self):
         return self._template.macros

Modified: megrok.chameleon/trunk/src/megrok/chameleon/tests/cpt_fixture/app.py
===================================================================
--- megrok.chameleon/trunk/src/megrok/chameleon/tests/cpt_fixture/app.py	2011-04-14 06:52:07 UTC (rev 121427)
+++ megrok.chameleon/trunk/src/megrok/chameleon/tests/cpt_fixture/app.py	2011-04-14 10:54:49 UTC (rev 121428)
@@ -49,3 +49,8 @@
     """A view with a template that uses macros.
     """
     pass
+
+class Namespace(grokcore.view.View):
+
+    def namespace(self):
+        return {'myname': 'Henk'}



More information about the checkins mailing list