[Checkins] SVN: zope.app.pagetemplate/trunk/ Moved named template implementation to zope.browserpage.
Hanno Schlichting
hannosch at hannosch.eu
Tue Dec 22 16:41:39 EST 2009
Log message for revision 106935:
Moved named template implementation to zope.browserpage.
Changed:
U zope.app.pagetemplate/trunk/CHANGES.txt
U zope.app.pagetemplate/trunk/setup.py
U zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/configure.zcml
U zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.py
D zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.txt
D zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/namedtemplate.pt
D zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/test_namedtemplate.py
-=-
Modified: zope.app.pagetemplate/trunk/CHANGES.txt
===================================================================
--- zope.app.pagetemplate/trunk/CHANGES.txt 2009-12-22 21:35:55 UTC (rev 106934)
+++ zope.app.pagetemplate/trunk/CHANGES.txt 2009-12-22 21:41:38 UTC (rev 106935)
@@ -2,9 +2,10 @@
Changes
=======
-3.9.1 (unreleased)
+3.10.0 (unreleased)
------------------
+- Moved named template implementation to zope.browserpage.
3.9.0 (2009-12-22)
------------------
Modified: zope.app.pagetemplate/trunk/setup.py
===================================================================
--- zope.app.pagetemplate/trunk/setup.py 2009-12-22 21:35:55 UTC (rev 106934)
+++ zope.app.pagetemplate/trunk/setup.py 2009-12-22 21:41:38 UTC (rev 106935)
@@ -22,7 +22,7 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-version = '3.9.1dev'
+version = '3.10.0dev'
setup(name='zope.app.pagetemplate',
@@ -34,8 +34,6 @@
long_description=(
read('README.txt')
+ '\n\n.. contents::\n\n' +
- read('src', 'zope', 'app', 'pagetemplate', 'namedtemplate.txt')
- + '\n\n' +
read('CHANGES.txt')
),
license='ZPL 2.1',
@@ -51,7 +49,7 @@
include_package_data=True,
install_requires=[
'setuptools',
- 'zope.browserpage>=3.10.1',
+ 'zope.browserpage>=3.11.0',
'zope.component [hook]',
'zope.configuration',
'zope.dublincore',
Modified: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/configure.zcml
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/configure.zcml 2009-12-22 21:35:55 UTC (rev 106934)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/configure.zcml 2009-12-22 21:41:38 UTC (rev 106935)
@@ -51,11 +51,4 @@
<allow attributes="__call__" />
</class>
- <!-- TALES namespace allows view/template:default etc -->
- <adapter
- for="*"
- factory=".namedtemplate.NamedTemplatePathAdapter"
- name="template"
- />
-
</configure>
Modified: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.py
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.py 2009-12-22 21:35:55 UTC (rev 106934)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.py 2009-12-22 21:41:38 UTC (rev 106935)
@@ -16,62 +16,9 @@
$Id$
"""
-from zope import component, interface
-import zope.traversing.interfaces
-
-class INamedTemplate(interface.Interface):
- """A template that is looked up by name
- """
-
-class NamedTemplateImplementation:
-
- def __init__(self, descriptor, view_type=None):
- try:
- descriptor.__get__
- except AttributeError:
- raise TypeError(
- "NamedTemplateImplementation must be passed a descriptor."
- )
- self.descriptor = descriptor
- interface.implementer(INamedTemplate)(self)
-
- if view_type is not None:
- component.adapter(view_type)(self)
-
- def __call__(self, instance):
- return self.descriptor.__get__(instance, instance.__class__)
-
-
-class implementation:
-
- def __init__(self, view_type=None):
- self.view_type = view_type
-
- def __call__(self, descriptor):
- return NamedTemplateImplementation(descriptor, self.view_type)
-
-
-class NamedTemplate(object):
-
- def __init__(self, name):
- self.__name__ = name
-
- def __get__(self, instance, type=None):
- if instance is None:
- return self
- return component.getAdapter(instance, INamedTemplate, self.__name__)
-
- def __call__(self, instance, *args, **kw):
- self.__get__(instance)(*args, **kw)
-
-
-# TODO need test
-class NamedTemplatePathAdapter(object):
-
- interface.implements(zope.traversing.interfaces.IPathAdapter)
-
- def __init__(self, context):
- self.context = context
-
- def __getitem__(self, name):
- return component.getAdapter(self.context, INamedTemplate, name)
+# BBB
+from zope.browerpage.namedtemplate import implementation
+from zope.browerpage.namedtemplate import INamedTemplate
+from zope.browerpage.namedtemplate import NamedTemplate
+from zope.browerpage.namedtemplate import NamedTemplateImplementation
+from zope.browerpage.namedtemplate import NamedTemplatePathAdapter
Deleted: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.txt
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.txt 2009-12-22 21:35:55 UTC (rev 106934)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.txt 2009-12-22 21:41:38 UTC (rev 106935)
@@ -1,73 +0,0 @@
-===============
-Named Templates
-===============
-
-We often want to be able to define view logic and view templates
-independently. We'd like to be able to change the template used by a
-form without being forced to modify the form.
-
-Named templates provide templates that are registered as named view
-adapters. To define a named template, use the `NamedTemplateImplementation`
-constructor:
-
- >>> from zope.browserpage import ViewPageTemplateFile
- >>> from zope.app.pagetemplate.namedtemplate import (
- ... NamedTemplateImplementation)
- >>> sample = ViewPageTemplateFile('tests/namedtemplate.pt')
- >>> sample = NamedTemplateImplementation(sample)
-
-Let's define a view that uses the named template. To use a named
-template, use the NamedTemplate constructor, and give a template name:
-
- >>> from zope.app.pagetemplate.namedtemplate import NamedTemplate
- >>> class MyView:
- ... def __init__(self, context, request):
- ... self.context = context
- ... self.request = request
- ...
- ... __call__ = NamedTemplate('sample')
-
-Normally, we'd register a named template for a view interface, to
-allow it to be registered for multiple views. We'll just register it
-for our view class.
-
- >>> from zope import component
- >>> component.provideAdapter(sample, [MyView], name='sample')
-
-Now, with this in place, we should be able to use our view:
-
- >>> class MyContent:
- ... def __init__(self, name):
- ... self.name = name
-
- >>> from zope.publisher.browser import TestRequest
- >>> print MyView(MyContent('bob'), TestRequest())(x=42)
- <html><body>
- Hello bob
- The URL is http://127.0.0.1
- The positional arguments were ()
- The keyword argument x is 42
- </body></html>
- <BLANKLINE>
-
-The view type that a named template is to be used for can be supplied
-when the named template is created:
-
- >>> class MyView:
- ... def __init__(self, context, request):
- ... self.context = context
- ... self.request = request
- ...
- ... __call__ = NamedTemplate('sample2')
-
- >>> sample = ViewPageTemplateFile('tests/namedtemplate.pt')
- >>> sample = NamedTemplateImplementation(sample, MyView)
- >>> component.provideAdapter(sample, name='sample2')
- >>> print MyView(MyContent('bob'), TestRequest())(x=42)
- <html><body>
- Hello bob
- The URL is http://127.0.0.1
- The positional arguments were ()
- The keyword argument x is 42
- </body></html>
- <BLANKLINE>
Deleted: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/namedtemplate.pt
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/namedtemplate.pt 2009-12-22 21:35:55 UTC (rev 106934)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/namedtemplate.pt 2009-12-22 21:41:38 UTC (rev 106935)
@@ -1,6 +0,0 @@
-<html><body>
-Hello <span tal:replace="context/name" />
-The URL is <span tal:replace="request/URL" />
-The positional arguments were <span tal:replace="args" />
-The keyword argument x is <span tal:replace="options/x" />
-</body></html>
Deleted: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/test_namedtemplate.py
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/test_namedtemplate.py 2009-12-22 21:35:55 UTC (rev 106934)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/test_namedtemplate.py 2009-12-22 21:41:38 UTC (rev 106935)
@@ -1,37 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005-2009 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.
-#
-##############################################################################
-"""
-
-$Id$
-"""
-import os
-import os.path
-import zope.component.testing
-import zope.traversing.adapters
-
-
-def pageSetUp(test):
- zope.component.testing.setUp(test)
- zope.component.provideAdapter(
- zope.traversing.adapters.DefaultTraversable,
- [None],
- )
-
-
-def test_suite():
- from zope.testing import doctest
- return doctest.DocFileSuite(
- os.path.join(os.pardir, 'namedtemplate.txt'),
- setUp=pageSetUp, tearDown=zope.component.testing.tearDown,
- )
More information about the checkins
mailing list