[Zope-Checkins]
SVN: Products.Five/branches/philikon-local-components/component/
get the template top-level variable namespace right and test it.
Philipp von Weitershausen
philikon at philikon.de
Wed Mar 1 18:17:06 EST 2006
Log message for revision 65688:
get the template top-level variable namespace right and test it.
improve some of the explanations in the doctest.
Changed:
UU Products.Five/branches/philikon-local-components/component/browser.py
U Products.Five/branches/philikon-local-components/component/component.txt
-=-
Modified: Products.Five/branches/philikon-local-components/component/browser.py
===================================================================
--- Products.Five/branches/philikon-local-components/component/browser.py 2006-03-01 23:07:35 UTC (rev 65687)
+++ Products.Five/branches/philikon-local-components/component/browser.py 2006-03-01 23:17:05 UTC (rev 65688)
@@ -125,29 +125,25 @@
self.context = context
self.request = request
-# def _zptNamespace(self):
-# root = aq_acquire(self.context, 'getPhysicalRoot')()
-# here = aq_inner(self.context)
-# view = self #XXX get the "real" view class
-# return {
-# 'template': self.viewzpt,
-# 'nothing': None,
-# 'request': request,
-# 'here': here,
-# 'context': here,
-# 'container': here,
-# 'view': view,
-# 'root': root,
-# 'modules': SecureModuleImporter,
-# }
+ def _zptNamespace(self):
+ root = aq_acquire(self.context, 'getPhysicalRoot')()
+ here = aq_inner(self.context)
+ view = self #XXX get the "real" view class
+ return {
+ 'template': self.viewzpt,
+ 'nothing': None,
+ 'request': self.request,
+ 'here': here,
+ 'context': here,
+ 'container': here,
+ 'view': view,
+ 'root': root,
+ 'modules': SecureModuleImporter,
+ }
def __call__(self, *args, **kwargs):
- view = self #XXX get the "real" view class
-
- namespace = self.viewzpt.pt_getContext()
+ namespace = self._zptNamespace()
if not kwargs.has_key('args'):
kwargs['args'] = args
namespace['options'] = kwargs
- namespace['view'] = view
-
return self.viewzpt.pt_render(namespace)
Property changes on: Products.Five/branches/philikon-local-components/component/browser.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: Products.Five/branches/philikon-local-components/component/component.txt
===================================================================
--- Products.Five/branches/philikon-local-components/component/component.txt 2006-03-01 23:07:35 UTC (rev 65687)
+++ Products.Five/branches/philikon-local-components/component/component.txt 2006-03-01 23:17:05 UTC (rev 65688)
@@ -17,6 +17,7 @@
>>> from OFS.Application import Application
>>> root = Application()
+
Turning ObjectManagers into a site
----------------------------------
@@ -25,14 +26,15 @@
>>> from OFS.ObjectManager import ObjectManager
>>> site = ObjectManager()
-We need to add it to the root:
+We need to add it to the root so that objects contained in it have a
+proper acquisition chain all the way to the top:
>>> id = root._setObject('site', site)
>>> site = root.site
-Make this a real site by using a view that a) sets
-``IObjectManagerSite``, b) sets a traversal hook and c) sets a
-component registration
+Now we make this a real site by using a view that a) sets
+``IObjectManagerSite``, b) sets a traversal hook and c) gives the site
+a component registration object (formerly known as site manager):
>>> import zope.component
>>> from zope.publisher.browser import TestRequest
@@ -80,7 +82,8 @@
Customizing views
-----------------
-We can select a view and see its template source:
+In the list of template-based browser views we can select one and see
+the source of its template:
>>> view = zope.component.getMultiAdapter((item, request),
... name=u"customizetemplate.html")
@@ -97,9 +100,9 @@
>>> zpt = view.doCustomizeTemplate(u'customizetemplate.html')
-That actually creates a ZPTPage object in the nearest site (perhaps
-later we'd like to have the option to pick which of the sites above us
-should be targeted)
+That actually creates a PageTemplate object in the nearest site
+(perhaps later we'd like to have the option to pick which of the sites
+above us should be targeted)
>>> zpt = getattr(site, 'customizetemplate.html')
>>> print zpt.read() #doctest: +ELLIPSIS
@@ -111,18 +114,40 @@
...
It also registers this component as a view now, so when we look up the
-view again, we get the customized one. Therefore let us customize the
-template and look up the view. For that to work, we also need to make
-the site the current site:
+view again, we get the customized one. Therefore let us actually
+change the template to give us some info output:
- >>> zpt.pt_edit('doctest\n', content_type=None)
+ >>> zpt.pt_edit("""
+ ... context: <tal:var replace="structure context" />
+ ... container: <tal:var replace="structure container" />
+ ... root: <tal:var replace="structure root" />
+ ... template: <tal:var replace="structure nocall:template" />
+ ... request: <tal:var replace="structure python:repr(request)" />
+ ... view: <tal:var replace="structure nocall:view" />
+ ... modules: <tal:var replace="structure modules" />
+ ... options: <tal:var replace="structure options" />
+ ... """, content_type=None)
+
+In order to be able to look up the customized view now, we need to
+make the site the current site:
+
>>> from zope.app.component.hooks import setSite
>>> setSite(site)
+
+Now look it up and compare its output:
+
>>> view = zope.component.getMultiAdapter((item, request),
... name=u"customizetemplate.html")
>>> view = view.__of__(item)
- >>> print view()
- doctest
+ >>> print view() #doctest: +ELLIPSIS
+ context: <SimpleContent at item>
+ container: <SimpleContent at item>
+ root: <Application at >
+ template: <ZopePageTemplate at customizetemplate.html>
+ request: <zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>
+ view: <Products.Five.component.browser.ZPTView object at ...>
+ modules: <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter instance at ...>
+ options: {'args': ()}
<BLANKLINE>
Clean up:
More information about the Zope-Checkins
mailing list