[Checkins] SVN: megrok.z3cpt/ Refactor work done on five.megrok.z3cpt to have an extension which works in Grok as well.

Sylvain Viollon sylvain at infrae.com
Sun Nov 23 16:00:50 EST 2008


Log message for revision 93284:
  Refactor work done on five.megrok.z3cpt to have an extension which works in Grok as well.
  
  

Changed:
  A   megrok.z3cpt/
  A   megrok.z3cpt/trunk/
  A   megrok.z3cpt/trunk/README.txt
  A   megrok.z3cpt/trunk/bootstrap.py
  A   megrok.z3cpt/trunk/buildout.cfg
  A   megrok.z3cpt/trunk/docs/
  A   megrok.z3cpt/trunk/docs/HISTORY.txt
  A   megrok.z3cpt/trunk/setup.py
  A   megrok.z3cpt/trunk/src/
  A   megrok.z3cpt/trunk/src/megrok/
  A   megrok.z3cpt/trunk/src/megrok/__init__.py
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/__init__.py
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/components.py
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/configure.zcml
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftesting.zcml
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/__init__.py
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/__init__.py
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/association.py
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/association_templates/
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/association_templates/painting.zpt
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/drawing.zpt
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/namespace.py
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/namespace_templates/
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/namespace_templates/namespace.zpt
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/simple.py
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/test_functional.py
  A   megrok.z3cpt/trunk/src/megrok/z3cpt/templatereg.py
  A   megrok.z3cpt/trunk/versions.cfg

-=-
Added: megrok.z3cpt/trunk/README.txt
===================================================================
--- megrok.z3cpt/trunk/README.txt	                        (rev 0)
+++ megrok.z3cpt/trunk/README.txt	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,44 @@
+megrok.z3cpt
+************
+
+``megrok.z3cpt`` is an extension providing `z3c.pt`_ templates in Grok
+and five.grok.
+
+You can define a `z3c.pt`_ template by:
+
+- Associating your template directly in your code::
+
+    import grok
+    from megrok import z3cpt
+
+    class Index(grok.View):
+        pass
+
+    index = z3cpt.PageTemplate("""Your template code""")
+
+- Specifying a file template::
+
+   index = z3cpt.PageTemplate(filename="template.zpt")
+
+- Creating your template with the extension ``.zpt`` in the
+  associated templates directory of the current module.
+
+Installation
+============
+
+You need to refer ``megrok.z3cpt`` as a dependency of your application
+and to load the following ZCML::
+
+  <include package="megrok.z3cpt" />
+
+Note
+----
+
+`z3c.pt`_ require at least `zope.i18n`_ 3.5. You need to override in
+your ``versions.cfg`` in order to prevent a conflict.
+
+For Zope 2 user, you need to specify `zope.i18n`_ in
+``skip-fake-eggs`` option of your Zope 2 installation.
+
+.. _zope.i18n: http://pypi.python.org/pypi/zope.i18n
+.. _z3c.pt: http://pypi.python.org/pypi/z3c.pt

Added: megrok.z3cpt/trunk/bootstrap.py
===================================================================
--- megrok.z3cpt/trunk/bootstrap.py	                        (rev 0)
+++ megrok.z3cpt/trunk/bootstrap.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 90478 2008-08-27 22:44:46Z georgyberdyshev $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+try:
+    import pkg_resources
+except ImportError:
+    ez = {}
+    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                         ).read() in ez
+    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+    import pkg_resources
+
+if sys.platform == 'win32':
+    def quote(c):
+        if ' ' in c:
+            return '"%s"' % c # work around spawn lamosity on windows
+        else:
+            return c
+else:
+    def quote (c):
+        return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws  = pkg_resources.working_set
+
+if is_jython:
+    import subprocess
+    
+    assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd', 
+           quote(tmpeggs), 'zc.buildout'], 
+           env=dict(os.environ,
+               PYTHONPATH=
+               ws.find(pkg_resources.Requirement.parse('setuptools')).location
+               ),
+           ).wait() == 0
+
+else:
+    assert os.spawnle(
+        os.P_WAIT, sys.executable, quote (sys.executable),
+        '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout',
+        dict(os.environ,
+            PYTHONPATH=
+            ws.find(pkg_resources.Requirement.parse('setuptools')).location
+            ),
+        ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)

Added: megrok.z3cpt/trunk/buildout.cfg
===================================================================
--- megrok.z3cpt/trunk/buildout.cfg	                        (rev 0)
+++ megrok.z3cpt/trunk/buildout.cfg	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,15 @@
+[buildout]
+develop = .
+parts = interpreter test
+extends = versions.cfg
+versions = versions
+
+[interpreter]
+recipe = zc.recipe.egg
+eggs = megrok.z3cpt
+interpreter = python
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = megrok.z3cpt [test]
+defaults = ['--tests-pattern', '^f?tests$', '-v']

Added: megrok.z3cpt/trunk/docs/HISTORY.txt
===================================================================
--- megrok.z3cpt/trunk/docs/HISTORY.txt	                        (rev 0)
+++ megrok.z3cpt/trunk/docs/HISTORY.txt	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,8 @@
+Changelog
+=========
+
+1.0  (unreleased)
+-----------------
+
+* Initial release
+

Added: megrok.z3cpt/trunk/setup.py
===================================================================
--- megrok.z3cpt/trunk/setup.py	                        (rev 0)
+++ megrok.z3cpt/trunk/setup.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,43 @@
+from setuptools import setup, find_packages
+import os
+
+version = '1.0dev'
+
+install_requires = [
+    'setuptools',
+    'grokcore.view',
+    'z3c.pt >= 1.0b4',
+    ]
+
+# The grok dependency is not added explicitly, so we can factor out a
+# version of this package for Zope 2 which is not going to install
+# grok. But we want the dependency to run tests.
+test_requires = install_requires + ['grok >= 0.14',]
+
+setup(name='megrok.z3cpt',
+      version=version,
+      description="z3c.pt support for Grok",
+      long_description=open("README.txt").read() + "\n" +
+                       open(os.path.join("docs", "HISTORY.txt")).read(),
+      # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+      classifiers=[
+          "Environment :: Web Environment",
+          "Intended Audience :: Developers",
+          "License :: OSI Approved :: Zope Public License",
+          "Programming Language :: Python",
+          "Topic :: Software Development :: Libraries :: Python Modules",
+          "Framework :: Zope3",
+          ],
+      keywords='pagetemplate grok',
+      author='Sylvain Viollon',
+      author_email='grok-dev at zope.org',
+      url='http://svn.zope.org/megrok.z3cpt',
+      license='ZPL',
+      packages=find_packages('src'),
+      package_dir = {'': 'src'},
+      namespace_packages=['megrok'],
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=install_requires,
+      extras_require={'test': test_requires,},
+      )

Added: megrok.z3cpt/trunk/src/megrok/__init__.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/__init__.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/__init__.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/__init__.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/__init__.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/__init__.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,15 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+from megrok.z3cpt.components import PageTemplate, PageTemplateFile

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/components.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/components.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/components.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,75 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+from z3c.pt.pagetemplate import ViewPageTemplate as Z3CViewPageTemplate
+from z3c.pt.pagetemplate import PageTemplateFile as Z3CPageTemplateFile
+from grokcore.view.components import PageTemplate as BasePageTemplate
+import martian
+
+import sys
+import os.path
+
+class ViewPageTemplate(Z3CViewPageTemplate):
+    """Grok let users define their namespace.
+    """
+
+    def _pt_get_context(self, view, request, kwargs):
+        default = kwargs.get('default_namespace', None)
+        if default:
+            del kwargs['default_namespace']
+        parameters = dict(
+            view=view,
+            context=view.context,
+            request=request or view.request,
+            template=self,
+            options=kwargs,
+            nothing=None)
+        if default:
+            parameters.update(default)
+        return parameters
+
+
+class ViewPageTemplateFile(ViewPageTemplate, Z3CPageTemplateFile):
+    """Let grok user defines their namespace.
+    """
+
+
+class PageTemplate(BasePageTemplate):
+    """A Grok z3c.pt template based.
+    """
+
+    def setFromString(self, string):
+        self._template = ViewPageTemplate(string)
+
+    def setFromFilename(self, filename, _prefix=None):
+        self._template = ViewPageTemplateFile(filename, _prefix)
+
+    def _initFactory(self, factory):
+        pass
+
+    def render(self, view):
+        namespace = self.getNamespace(view)
+        return self._template(view, default_namespace=namespace)
+
+
+class PageTemplateFile(PageTemplate):
+    """A Grok Page template file.
+    """
+    # For BBB
+    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)

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/configure.zcml
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/configure.zcml	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/configure.zcml	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,13 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:grok="http://namespaces.zope.org/grok">
+
+  <include package="z3c.pt" />
+
+  <!-- We use meta-minimal so the extension is available for Zope 2 as well -->
+  <include package="grokcore.view" file="meta-minimal.zcml" />
+  <include package="grokcore.view" />
+
+  <grok:grok package=".templatereg" />
+
+</configure>

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftesting.zcml
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftesting.zcml	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftesting.zcml	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,47 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:grok="http://namespaces.zope.org/grok"
+   xmlns:browser="http://namespaces.zope.org/browser"
+   i18n_domain="megrok.z3cpt"
+   package="megrok.z3cpt"
+   >
+
+  <include package="zope.app.zcmlfiles" file="meta.zcml" />
+  <include package="zope.securitypolicy" file="meta.zcml" />
+
+  <include package="zope.app.zcmlfiles" />
+  <include package="zope.app.authentication" />
+  <include package="grok" />
+  <include package="megrok.z3cpt" />
+  <grok:grok package="megrok.z3cpt.ftests" />
+
+  <securityPolicy
+      component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy"
+      />
+
+  <browser:defaultView
+      for="grokcore.component.interfaces.IContext"
+      name="index"
+      />
+
+  <unauthenticatedPrincipal
+      id="zope.anybody"
+      title="Unauthenticated User"
+      />
+  <grant
+      permission="zope.View"
+      principal="zope.anybody"
+      />
+
+  <principal
+      id="zope.mgr"
+      title="Manager"
+      login="mgr"
+      password="mgrpw"
+      />
+
+  <role id="zope.Manager" title="Site Manager" />
+  <grantAll role="zope.Manager" />
+  <grant role="zope.Manager" principal="zope.mgr" />
+
+</configure>

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/__init__.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/__init__.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/__init__.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1 @@
+# This is a package

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/__init__.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/__init__.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/__init__.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1 @@
+# This is a package

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/association.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/association.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/association.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,58 @@
+"""
+  >>> from megrok.z3cpt.ftests.templates.association import *
+  >>> getRootFolder()["manfred"] = Mammoth()
+
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+  >>> browser.handleErrors = False
+  >>> browser.open("http://localhost/manfred/@@painting")
+  >>> print browser.contents
+  <html>
+  <body>
+  <h1>Hello Paul!</h1>
+  </body>
+  </html>
+  >>> browser.open("http://localhost/manfred/@@drawing")
+  >>> print browser.contents
+  <html>
+  <body>
+  <h1>I am a regular drawing!</h1>
+  </body>
+  </html>
+  >>> browser.open("http://localhost/manfred/@@sketch")
+  >>> print browser.contents
+  <html>
+  <body>
+  <h1>I am a rapidly executed freehand drawing!</h1>
+  </body>
+  </html>
+
+"""
+
+import grok
+from megrok import z3cpt
+
+class Mammoth(grok.Model):
+    pass
+
+
+class Painting(grok.View):
+
+    def name(self):
+        return u"Paul"
+
+
+class Drawing(grok.View):
+
+    def kind(self):
+        return u'regular drawing'
+
+drawing = z3cpt.PageTemplateFile("drawing.zpt")
+
+
+class Sketch(grok.View):
+
+    def kind(self):
+        return u'rapidly executed freehand drawing'
+
+sketch = z3cpt.PageTemplate(filename="drawing.zpt")

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/association_templates/painting.zpt
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/association_templates/painting.zpt	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/association_templates/painting.zpt	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,6 @@
+<html>
+<body>
+<h1>Hello ${view/name}!</h1>
+</body>
+</html>
+

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/drawing.zpt
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/drawing.zpt	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/drawing.zpt	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,6 @@
+<html>
+<body>
+<h1>I am a ${view/kind}!</h1>
+</body>
+</html>
+

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/namespace.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/namespace.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/namespace.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,46 @@
+"""
+  >>> from megrok.z3cpt.ftests.templates.namespace import *
+  >>> getRootFolder()["manfred"] = Mammoth()
+
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+  >>> browser.handleErrors = False
+  >>> browser.open("http://localhost/manfred/@@painting")
+  >>> print browser.contents
+  <html>
+  <body>
+  <h1>Hello Henri</h1>
+  </body>
+  </html>
+  >>> browser.open("http://localhost/manfred/@@drawing")
+  >>> print browser.contents
+  <html>
+  <body>
+  <h1>Hello Jean</h1>
+  </body>
+  </html>
+
+"""
+
+import grok
+from megrok import z3cpt
+
+class Mammoth(grok.Model):
+    pass
+
+
+class Painting(grok.View):
+
+    grok.template('namespace')
+
+    def default_namespace(self):
+        return dict(name=u'Henri')
+
+
+class Drawing(grok.View):
+
+    grok.template('namespace')
+
+    def namespace(self):
+        return dict(name='Jean')
+

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/namespace_templates/namespace.zpt
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/namespace_templates/namespace.zpt	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/namespace_templates/namespace.zpt	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,5 @@
+<html>
+<body>
+<h1>Hello ${name}</h1>
+</body>
+</html>

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/simple.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/simple.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/templates/simple.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,57 @@
+"""
+  >>> from megrok.z3cpt.ftests.templates.simple import *
+  >>> getRootFolder()["manfred"] = Mammoth()
+
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+  >>> browser.handleErrors = False
+  >>> browser.open("http://localhost/manfred/@@painting")
+  >>> print browser.contents
+  <html>
+  <body>
+  <h1>Hello World</h1>
+  </body>
+  </html>
+  >>> browser.open("http://localhost/manfred/@@drawing")
+  >>> print browser.contents
+  <html>
+  <body>
+  <h1>Hello World</h1>
+  <p>Nothing for the moment</p>
+  </body>
+  </html>
+
+"""
+
+import grok
+from megrok import z3cpt
+
+class Mammoth(grok.Model):
+    pass
+
+
+class Painting(grok.View):
+    pass
+
+painting = z3cpt.PageTemplate("""
+<html>
+<body>
+<h1>Hello World</h1>
+</body>
+</html>
+""")
+
+class Drawing(grok.View):
+
+    @property
+    def description(self):
+        return u'Nothing for the moment'
+
+drawing = z3cpt.PageTemplate("""
+<html>
+<body>
+<h1>Hello World</h1>
+<p tal:content="view/description">Description</p>
+</body>
+</html>
+""")

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/test_functional.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/test_functional.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/ftests/test_functional.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,58 @@
+import re
+import unittest
+import os.path
+import megrok.z3cpt
+
+from pkg_resources import resource_listdir
+from zope.testing import doctest, renormalizing
+from zope.app.testing.functional import (HTTPCaller, getRootFolder,
+                                         FunctionalTestSetup, sync, ZCMLLayer)
+
+ftesting_zcml = os.path.join(os.path.dirname(megrok.z3cpt.__file__),
+                             'ftesting.zcml')
+FunctionalLayer = ZCMLLayer(ftesting_zcml, __name__, 'FunctionalLayer',
+                            allow_teardown=True)
+
+def setUp(test):
+    FunctionalTestSetup().setUp()
+
+def tearDown(test):
+    FunctionalTestSetup().tearDown()
+
+checker = renormalizing.RENormalizing([
+    # Accommodate to exception wrapping in newer versions of mechanize
+    (re.compile(r'httperror_seek_wrapper:', re.M), 'HTTPError:'),
+    ])
+
+def suiteFromPackage(name):
+    files = resource_listdir(__name__, name)
+    suite = unittest.TestSuite()
+    for filename in files:
+        if not filename.endswith('.py'):
+            continue
+        if filename == '__init__.py':
+            continue
+        if filename[0] in ('.', '#',):
+            continue
+
+        dottedname = 'megrok.z3cpt.ftests.%s.%s' % (name, filename[:-3])
+        test = doctest.DocTestSuite(
+            dottedname, setUp=setUp, tearDown=tearDown,
+            checker=checker,
+            extraglobs=dict(http=HTTPCaller(),
+                            getRootFolder=getRootFolder,
+                            sync=sync),
+            optionflags=(doctest.ELLIPSIS+
+                         doctest.NORMALIZE_WHITESPACE+
+                         doctest.REPORT_NDIFF)
+            )
+        test.layer = FunctionalLayer
+
+        suite.addTest(test)
+    return suite
+
+def test_suite():
+    suite = unittest.TestSuite()
+    for name in ['templates',]:
+        suite.addTest(suiteFromPackage(name))
+    return suite

Added: megrok.z3cpt/trunk/src/megrok/z3cpt/templatereg.py
===================================================================
--- megrok.z3cpt/trunk/src/megrok/z3cpt/templatereg.py	                        (rev 0)
+++ megrok.z3cpt/trunk/src/megrok/z3cpt/templatereg.py	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+from zope.interface import implements
+from grokcore.view.interfaces import ITemplateFileFactory
+from megrok.z3cpt import PageTemplate
+import grokcore.component
+
+
+class ZopeTwoPageTemplateFileFactory(grokcore.component.GlobalUtility):
+    implements(ITemplateFileFactory)
+    grokcore.component.name('zpt')
+
+    def __call__(self, filename, _prefix=None):
+        return PageTemplate(filename=filename, _prefix=_prefix)

Added: megrok.z3cpt/trunk/versions.cfg
===================================================================
--- megrok.z3cpt/trunk/versions.cfg	                        (rev 0)
+++ megrok.z3cpt/trunk/versions.cfg	2008-11-23 21:00:50 UTC (rev 93284)
@@ -0,0 +1,109 @@
+[versions]
+ClientForm = 0.2.9
+Pygments = 0.8.1
+RestrictedPython = 3.4.2
+ZConfig = 2.5.1
+ZODB3 = 3.8
+docutils = 0.4
+grokcore.component = 1.5.1
+grokcore.security = 1.0
+grokcore.view = 1.2
+martian = 0.11
+mechanize = 0.1.7b
+pytz = 2007k
+simplejson = 1.7.1
+z3c.autoinclude = 0.2.2
+z3c.flashmessage = 1.0
+z3c.testsetup = 0.2.1
+zc.catalog = 1.2
+zc.recipe.testrunner = 1.0.0
+zdaemon = 2.0.2
+zodbcode = 3.4
+zope.annotation = 3.4.1
+zope.app.apidoc = 3.4.3
+zope.app.applicationcontrol = 3.4.3
+zope.app.appsetup = 3.4.1
+zope.app.authentication = 3.4.3
+zope.app.basicskin = 3.4
+zope.app.broken = 3.4
+zope.app.catalog = 3.5.1
+zope.app.component = 3.4.1
+zope.app.container = 3.5.6
+zope.app.content = 3.4
+zope.app.debug = 3.4.1
+zope.app.dependable = 3.4
+zope.app.error = 3.5.1
+zope.app.exception = 3.4.1
+zope.app.file = 3.4.4
+zope.app.folder = 3.4
+zope.app.form = 3.4.1
+zope.app.generations = 3.4.1
+zope.app.http = 3.4.1
+zope.app.i18n = 3.4.4
+zope.app.interface = 3.4
+zope.app.intid = 3.4.1
+zope.app.keyreference = 3.4.1
+zope.app.locales = 3.4.5
+zope.app.onlinehelp = 3.4.1
+zope.app.pagetemplate = 3.4.1
+zope.app.preference = 3.4.1
+zope.app.principalannotation = 3.4
+zope.app.publication = 3.4.3
+zope.app.publisher = 3.4.1
+zope.app.renderer = 3.4
+zope.app.rotterdam = 3.4.1
+zope.app.schema = 3.4
+zope.app.security = 3.5.2
+zope.app.securitypolicy = 3.4.6
+zope.app.server = 3.4.2
+zope.app.session = 3.5.1
+zope.app.skins = 3.4
+zope.app.testing = 3.4.3
+zope.app.tree = 3.4
+zope.app.twisted = 3.4.1
+zope.app.wsgi = 3.4.1
+zope.app.zapi = 3.4
+zope.app.zcmlfiles = 3.4.3
+zope.app.zopeappgenerations = 3.4
+zope.cachedescriptors = 3.4.1
+zope.component = 3.4
+zope.configuration = 3.4
+zope.contentprovider = 3.4
+zope.contenttype = 3.4
+zope.copypastemove = 3.4
+zope.datetime = 3.4
+zope.deferredimport = 3.4
+zope.deprecation = 3.4
+zope.dottedname = 3.4.2
+zope.dublincore = 3.4
+zope.error = 3.5.1
+zope.event = 3.4
+zope.exceptions = 3.4
+zope.filerepresentation = 3.4
+zope.formlib = 3.4
+zope.hookable = 3.4
+zope.i18n = 3.5
+zope.i18nmessageid = 3.4.3
+zope.index = 3.4.1
+zope.interface = 3.4.1
+zope.lifecycleevent = 3.4
+zope.location = 3.4
+zope.minmax = 1.1
+zope.modulealias = 3.4
+zope.pagetemplate = 3.4
+zope.proxy = 3.4.2
+zope.publisher = 3.4.6
+zope.schema = 3.4
+zope.security = 3.4.1
+zope.securitypolicy = 3.4.1
+zope.server = 3.4.3
+zope.session = 3.4.1
+zope.size = 3.4
+zope.structuredtext = 3.4
+zope.tal = 3.4.1
+zope.tales = 3.4
+zope.testbrowser = 3.4.2
+zope.testing = 3.5.4
+zope.thread = 3.4
+zope.traversing = 3.4.1
+zope.viewlet = 3.4.2



More information about the Checkins mailing list