[Checkins] SVN: five.pt/trunk/src/five/pt/ Get in the first ugly version of a z3c.pt based ViewPageTemplateFile for Zope 2 :)

Hanno Schlichting plone at hannosch.info
Tue Aug 12 17:25:48 EDT 2008


Log message for revision 89755:
  Get in the first ugly version of a z3c.pt based ViewPageTemplateFile for Zope 2 :)
  

Changed:
  A   five.pt/trunk/src/five/pt/pagetemplate.py
  A   five.pt/trunk/src/five/pt/tests/
  A   five.pt/trunk/src/five/pt/tests/__init__.py
  A   five.pt/trunk/src/five/pt/tests/simple.pt
  A   five.pt/trunk/src/five/pt/tests/test_pagetemplatefile.py

-=-
Added: five.pt/trunk/src/five/pt/pagetemplate.py
===================================================================
--- five.pt/trunk/src/five/pt/pagetemplate.py	                        (rev 0)
+++ five.pt/trunk/src/five/pt/pagetemplate.py	2008-08-12 21:25:46 UTC (rev 89755)
@@ -0,0 +1,70 @@
+import os
+import sys
+
+from zope.app.pagetemplate.viewpagetemplatefile import ViewMapper
+
+from Acquisition import aq_inner
+from Acquisition import Implicit
+from Globals import package_home
+from OFS.Traversable import Traversable
+
+from Products.PageTemplates.Expressions import SecureModuleImporter
+
+import z3c.pt.pagetemplate
+
+
+class ZopeViewPageTemplateFile(
+    z3c.pt.pagetemplate.PageTemplateFile,
+    Implicit,
+    Traversable):
+
+    default_expression = 'path'
+
+
+class ViewPageTemplateFile(property):
+
+    def __init__(self, filename, **kwargs):
+        path = self.get_path_from_prefix(None)
+        filename = os.path.join(path, filename)
+        self.template = ZopeViewPageTemplateFile(filename)
+        property.__init__(self, self.render)
+
+    def get_path_from_prefix(self, _prefix):
+        if isinstance(_prefix, str):
+            path = _prefix
+        else:
+            if _prefix is None:
+                _prefix = sys._getframe(2).f_globals
+            path = package_home(_prefix)
+        return path
+
+    def render(self, view):
+        try:
+            root = self.getPhysicalRoot()
+        except AttributeError:
+            try:
+                root = view.context.getPhysicalRoot()
+            except AttributeError:
+                root = None
+
+        context = aq_inner(view.context)
+
+        def template(**kwargs):
+            return self.template.render(
+                view=view,
+                context=context,
+                request=view.request,
+                _context=view.request,
+                template=self,
+                here=context,
+                container=context,
+                nothing=None,
+                root=root,
+                modules=SecureModuleImporter,
+                views=ViewMapper(context, view.request),
+                options=kwargs)
+
+        return template
+
+    def __call__(self):
+        return self.render()


Property changes on: five.pt/trunk/src/five/pt/pagetemplate.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: five.pt/trunk/src/five/pt/tests/__init__.py
===================================================================
--- five.pt/trunk/src/five/pt/tests/__init__.py	                        (rev 0)
+++ five.pt/trunk/src/five/pt/tests/__init__.py	2008-08-12 21:25:46 UTC (rev 89755)
@@ -0,0 +1 @@
+#
\ No newline at end of file


Property changes on: five.pt/trunk/src/five/pt/tests/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: five.pt/trunk/src/five/pt/tests/simple.pt
===================================================================
--- five.pt/trunk/src/five/pt/tests/simple.pt	                        (rev 0)
+++ five.pt/trunk/src/five/pt/tests/simple.pt	2008-08-12 21:25:46 UTC (rev 89755)
@@ -0,0 +1,4 @@
+<div xmlns="http://www.w3.org/1999/xhtml"
+     xmlns:tal="http://xml.zope.org/namespaces/tal">
+    Hello World
+</div>


Property changes on: five.pt/trunk/src/five/pt/tests/simple.pt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: five.pt/trunk/src/five/pt/tests/test_pagetemplatefile.py
===================================================================
--- five.pt/trunk/src/five/pt/tests/test_pagetemplatefile.py	                        (rev 0)
+++ five.pt/trunk/src/five/pt/tests/test_pagetemplatefile.py	2008-08-12 21:25:46 UTC (rev 89755)
@@ -0,0 +1,34 @@
+import unittest
+
+from Products.Five import BrowserView
+from Testing.ZopeTestCase import ZopeTestCase
+
+from five.pt.pagetemplate import ViewPageTemplateFile
+
+
+class SimpleView(BrowserView):
+
+    index = ViewPageTemplateFile('simple.pt')
+
+
+class TestPageTemplateFile(ZopeTestCase):
+
+    def afterSetUp(self):
+        from Products.Five import zcml
+        import Products.Five
+        import z3c.pt
+        zcml.load_config("configure.zcml", Products.Five)
+        zcml.load_config("configure.zcml", z3c.pt)
+
+    def test_simplefile(self):
+        context = self.folder
+        request = context.REQUEST
+
+        view = SimpleView(context, request)
+        result = view.index()
+        self.failUnless('Hello World' in result)
+
+
+def test_suite():
+    import sys
+    return unittest.findTestCases(sys.modules[__name__])


Property changes on: five.pt/trunk/src/five/pt/tests/test_pagetemplatefile.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list