[Checkins] SVN: five.grok/branches/sylvain-static-and-forms/src/five/grok/ - Namespace should use first the namespace collected on the view, than the one collected by the template engine for Zope 2 page templates. Otherwise, you can't implements stuff like content provider or viewlets.
Sylvain Viollon
sylvain at infrae.com
Sun Aug 24 18:36:29 EDT 2008
Log message for revision 90179:
- Namespace should use first the namespace collected on the view, than the one collected by the template engine for Zope 2 page templates. Otherwise, you can't implements stuff like content provider or viewlets.
- As well, the namespace should not end up in options.
Changed:
U five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py
A five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/namespace.py
-=-
Modified: five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py
===================================================================
--- five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py 2008-08-24 18:40:06 UTC (rev 90178)
+++ five.grok/branches/sylvain-static-and-forms/src/five/grok/components.py 2008-08-24 22:36:27 UTC (rev 90179)
@@ -10,7 +10,8 @@
from grokcore.view.components import PageTemplate
import grokcore.view
-from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile \
+ as BaseViewPageTemplateFile
from Products.Five.browser.pagetemplatefile import getEngine
from Products.Five.browser import resource
from Products.Five.formlib import formbase
@@ -65,9 +66,21 @@
c['view'] = view
c['views'] = ViewMapper(here, request)
+ if hasattr(self, 'pt_grokContext'):
+ c.update(self.pt_grokContext)
+
return c
+class ViewPageTemplateFile(BaseViewPageTemplateFile):
+
+ def pt_getContext(self):
+ c = super(ViewPageTemplateFile, self).pt_getContext()
+ if hasattr(self, 'pt_grokContext'):
+ c.update(self.pt_grokContext)
+
+ return c
+
class ZopeTwoPageTemplate(PageTemplate):
def setFromString(self, string):
@@ -79,8 +92,8 @@
def render(self, view):
namespace = self.getNamespace(view)
template = self._template.__of__(view)
- namespace.update(template.pt_getContext())
- return template(namespace)
+ template.pt_grokContext = namespace
+ return template()
class DirectoryResource(resource.DirectoryResource):
Added: five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/namespace.py
===================================================================
--- five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/namespace.py (rev 0)
+++ five.grok/branches/sylvain-static-and-forms/src/five/grok/ftests/view/namespace.py 2008-08-24 22:36:27 UTC (rev 90179)
@@ -0,0 +1,36 @@
+"""
+ >>> from five.grok.ftests.view.namespace import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/manfred")
+ >>> print browser.contents
+ <html>
+ <body>
+ <h1>Hello I am manfred!</h1>
+ </body>
+ </html>
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+
+ def __init__(self, id):
+ super(Mammoth, self).__init__(id)
+ self.id = id
+
+class Index(grok.View):
+
+ def namespace(self):
+ return {'name': self.context.id}
+
+index = grok.PageTemplate("""\
+<html>
+<body>
+<h1>Hello I am <tal:name tal:replace="name" />!</h1>
+</body>
+</html>
+""")
More information about the Checkins
mailing list