[Checkins] SVN: five.grok/trunk/ Fix grok.PageTemplateFile to behave like grok.PageTemplate (use the template engine).
Sylvain Viollon
sylvain at infrae.com
Sat Nov 15 09:30:05 EST 2008
Log message for revision 92972:
Fix grok.PageTemplateFile to behave like grok.PageTemplate (use the template engine).
Changed:
U five.grok/trunk/docs/HISTORY.txt
U five.grok/trunk/src/five/grok/__init__.py
U five.grok/trunk/src/five/grok/components.py
U five.grok/trunk/src/five/grok/ftests/view/view.py
-=-
Modified: five.grok/trunk/docs/HISTORY.txt
===================================================================
--- five.grok/trunk/docs/HISTORY.txt 2008-11-15 14:21:58 UTC (rev 92971)
+++ five.grok/trunk/docs/HISTORY.txt 2008-11-15 14:30:04 UTC (rev 92972)
@@ -7,6 +7,11 @@
* Added support for viewlets with `grokcore.viewlet`_.
[thefunny42]
+* Added support for using Zope 2 templates by default when doing ``from
+ five import grok`` and using grok.PageTemplateFile (being consistent
+ with grok.PageTemplate).
+ [thefunny42]
+
five.grok - 1.0a1 (2008-10-22)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -17,7 +22,7 @@
[thefunny42]
* Added support for inline templates and made Zope 2 template semantics
- the default when doing 'from five import grok' and using
+ the default when doing ``from five import grok`` and using
grok.PageTemplate.
[optilude]
Modified: five.grok/trunk/src/five/grok/__init__.py
===================================================================
--- five.grok/trunk/src/five/grok/__init__.py 2008-11-15 14:21:58 UTC (rev 92971)
+++ five.grok/trunk/src/five/grok/__init__.py 2008-11-15 14:30:04 UTC (rev 92972)
@@ -24,4 +24,5 @@
# Override the one from grokcore.view so that we get Zope 2 semantics
from five.grok.components import ZopeTwoPageTemplate as PageTemplate
+from five.grok.components import ZopeTwoPageTemplateFile as PageTemplateFile
Modified: five.grok/trunk/src/five/grok/components.py
===================================================================
--- five.grok/trunk/src/five/grok/components.py 2008-11-15 14:21:58 UTC (rev 92971)
+++ five.grok/trunk/src/five/grok/components.py 2008-11-15 14:30:04 UTC (rev 92972)
@@ -13,7 +13,11 @@
##############################################################################
import martian
+import martian.util
+import os.path
+import sys
+
from zope.annotation.interfaces import IAttributeAnnotatable
from zope.viewlet.interfaces import IViewletManager, IViewlet
from zope.security.interfaces import IPermission
@@ -130,6 +134,16 @@
return template()
+class ZopeTwoPageTemplateFile(ZopeTwoPageTemplate):
+
+ def __init__(self, filename, _prefix=None):
+ self.__grok_module__ = martian.util.caller_module()
+ if _prefix is None:
+ module = sys.modules[self.__grok_module__]
+ _prefix = os.path.dirname(module.__file__)
+ self.setFromFilename(filename, _prefix)
+
+
class DirectoryResource(resource.DirectoryResource):
# We subclass this, because we want to override the default factories for
# the resources so that .pt and .html do not get created as page
Modified: five.grok/trunk/src/five/grok/ftests/view/view.py
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/view.py 2008-11-15 14:21:58 UTC (rev 92971)
+++ five.grok/trunk/src/five/grok/ftests/view/view.py 2008-11-15 14:30:04 UTC (rev 92972)
@@ -9,7 +9,7 @@
>>> print browser.contents
<html>
<body>
- <h1>Hello, world!</h1>
+ <h1>Hello, world manfred!</h1>
</body>
</html>
@@ -17,15 +17,19 @@
from five import grok
class Mammoth(grok.Model):
- pass
+ def __init__(self, id):
+ super(Mammoth, self).__init__(id=id)
+ self.id = id
+
+
class Painting(grok.View):
pass
painting = grok.PageTemplate("""\
<html>
<body>
-<h1>Hello, world!</h1>
+<h1>Hello, world <tal:replace tal:replace="here/id" />!</h1>
</body>
</html>
""")
More information about the Checkins
mailing list