Log message for revision 85468: Improve doctest paragraph about calling templates that are instance variables.
Changed: U Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py U Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml U Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt -=- Modified: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py =================================================================== --- Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py 2008-04-18 12:43:22 UTC (rev 85467) +++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py 2008-04-18 12:53:20 UTC (rev 85468) @@ -49,12 +49,13 @@ def __call__(self): return self.template() -class LegacyTemplateTwo(BrowserView): +class InstanceTemplate(BrowserView): def __init__(self, context, request): self.__parent__ = context self.context = context self.request = request + # This is wrong (even though it used to work before): self.template = ViewPageTemplateFile('falcon.pt') def __call__(self): Modified: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml =================================================================== --- Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml 2008-04-18 12:43:22 UTC (rev 85467) +++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml 2008-04-18 12:53:20 UTC (rev 85468) @@ -24,8 +24,8 @@ <browser:page for="*" - name="template_two" - class=".aqlegacy.LegacyTemplateTwo" + name="instance_template" + class=".aqlegacy.InstanceTemplate" permission="zope.Public" /> Modified: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt =================================================================== --- Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt 2008-04-18 12:43:22 UTC (rev 85467) +++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt 2008-04-18 12:53:20 UTC (rev 85468) @@ -166,37 +166,35 @@ Testing keyword arguments ========================= -ViewPageTemplateFile's take arbitrary keyword arguments: +Instances of ViewPageTemplateFile can be accessed from outside the +view and called. They take arbitrary keyword arguments: >>> view = getMultiAdapter((self.folder, request), name='template') >>> template = view.template >>> print template(foo=1, bar=2) <p>The falcon has taken flight</p> -Passing in an argument called instance was supported by the old Five version -of ViewPageTemplateFile, so we still need to support it. +Passing in an argument called ``instance`` was supported by the old +Five version of ViewPageTemplateFile, so we still need to support it: -In the zope.app.pagetemplate version, the first required argument is called -instance, though. - >>> print template(instance='allowed') <p>The falcon has taken flight</p> -No arguments required -===================== +Class-level templates only +========================== -ViewPageTemplateFile's require no arguments, but you can only use them as -class variables: +ViewPageTemplateFile instances can only be used as class attributes. +If you put one on an instance (as does the following view), you'll get +a ``TypeError`` when you try to render the template: - >>> view = getMultiAdapter((self.folder, request), name='template_two') + >>> view = getMultiAdapter((self.folder, request), name='instance_template') >>> print view() Traceback (most recent call last): ... TypeError: __call__() takes at least 2 arguments (1 given) - Clean up -------- _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins