[Zope3-checkins] SVN: zope.formlib/trunk/ - Moved ``namedtemplate`` to ``zope.app.pagetemplate``, to cut some
Michael Howitz
mh at gocept.com
Mon May 18 16:01:54 EDT 2009
Log message for revision 100109:
- Moved ``namedtemplate`` to ``zope.app.pagetemplate``, to cut some
dependencies on ``zope.formlib`` when using this feature. Left BBB
imports here.
Changed:
U zope.formlib/trunk/CHANGES.txt
U zope.formlib/trunk/setup.py
U zope.formlib/trunk/src/zope/formlib/configure.zcml
U zope.formlib/trunk/src/zope/formlib/form.py
U zope.formlib/trunk/src/zope/formlib/namedtemplate.py
D zope.formlib/trunk/src/zope/formlib/namedtemplate.txt
D zope.formlib/trunk/src/zope/formlib/sample.pt
U zope.formlib/trunk/src/zope/formlib/tests.py
-=-
Modified: zope.formlib/trunk/CHANGES.txt
===================================================================
--- zope.formlib/trunk/CHANGES.txt 2009-05-18 20:01:21 UTC (rev 100108)
+++ zope.formlib/trunk/CHANGES.txt 2009-05-18 20:01:53 UTC (rev 100109)
@@ -11,6 +11,11 @@
``zope.browser.interfaces``) instead. Depend on
``zope.browser>=1.1`` (the version with ``IAdding``).
+- Moved ``namedtemplate`` to ``zope.app.pagetemplate``, to cut some
+ dependencies on ``zope.formlib`` when using this feature. Left BBB
+ imports here.
+
+
3.5.2 (2009-02-21)
==================
Modified: zope.formlib/trunk/setup.py
===================================================================
--- zope.formlib/trunk/setup.py 2009-05-18 20:01:21 UTC (rev 100108)
+++ zope.formlib/trunk/setup.py 2009-05-18 20:01:53 UTC (rev 100109)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2006 Zope Corporation and Contributors.
+# Copyright (c) 2006-2009 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -21,8 +21,10 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+version = '3.6.0dev'
+
setup(name='zope.formlib',
- version = '3.5.3dev',
+ version=version,
url='http://pypi.python.org/pypi/zope.formlib',
license='ZPL 2.1',
description='Form generation and validation library for Zope',
@@ -35,10 +37,7 @@
read('src', 'zope', 'formlib', 'form.txt')
+ '\n\n' +
read('src', 'zope', 'formlib', 'errors.txt')
- + '\n\n' +
- read('src', 'zope', 'formlib', 'namedtemplate.txt')
),
-
packages=find_packages('src'),
package_dir = {'': 'src'},
namespace_packages=['zope',],
@@ -48,7 +47,7 @@
install_requires=['setuptools',
'pytz',
'zope.app.form',
- 'zope.app.pagetemplate',
+ 'zope.app.pagetemplate>=3.6.0',
'zope.component',
'zope.event',
'zope.i18n',
Modified: zope.formlib/trunk/src/zope/formlib/configure.zcml
===================================================================
--- zope.formlib/trunk/src/zope/formlib/configure.zcml 2009-05-18 20:01:21 UTC (rev 100108)
+++ zope.formlib/trunk/src/zope/formlib/configure.zcml 2009-05-18 20:01:53 UTC (rev 100109)
@@ -7,13 +7,6 @@
<adapter factory=".form.default_subpage_template" name="default" />
<adapter factory=".form.render_submit_button" name="render" />
- <!-- TALES namespace allows view/template:default etc -->
- <adapter
- for="*"
- factory=".namedtemplate.NamedTemplatePathAdapter"
- name="template"
- />
-
<!-- Error view for 'Invalid' -->
<adapter
factory=".errors.InvalidErrorView"
Modified: zope.formlib/trunk/src/zope/formlib/form.py
===================================================================
--- zope.formlib/trunk/src/zope/formlib/form.py 2009-05-18 20:01:21 UTC (rev 100108)
+++ zope.formlib/trunk/src/zope/formlib/form.py 2009-05-18 20:01:53 UTC (rev 100109)
@@ -39,9 +39,9 @@
from zope.app.form.interfaces import IInputWidget, IDisplayWidget
from zope.app.form.interfaces import WidgetsError, MissingInputError
from zope.app.form.interfaces import InputErrors, WidgetInputError
-from zope.app.pagetemplate import ViewPageTemplateFile
+from zope.app.pagetemplate import ViewPageTemplateFile, namedtemplate
-from zope.formlib import interfaces, namedtemplate
+from zope.formlib import interfaces
from zope.i18nmessageid import MessageFactory
_ = MessageFactory("zope")
@@ -532,7 +532,7 @@
field.set(adapter, newvalue)
return descriptions
-
+
def applyChanges(context, form_fields, data, adapters=None):
return bool(applyData(context, form_fields, data, adapters))
Modified: zope.formlib/trunk/src/zope/formlib/namedtemplate.py
===================================================================
--- zope.formlib/trunk/src/zope/formlib/namedtemplate.py 2009-05-18 20:01:21 UTC (rev 100108)
+++ zope.formlib/trunk/src/zope/formlib/namedtemplate.py 2009-05-18 20:01:53 UTC (rev 100109)
@@ -1,6 +1,7 @@
##############################################################################
#
-# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+# 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.
@@ -15,62 +16,7 @@
$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.app.pagetemplate.namedtemplate import (
+ INamedTemplate, NamedTemplateImplementation, implementation,
+ NamedTemplate, NamedTemplatePathAdapter)
Deleted: zope.formlib/trunk/src/zope/formlib/namedtemplate.txt
===================================================================
--- zope.formlib/trunk/src/zope/formlib/namedtemplate.txt 2009-05-18 20:01:21 UTC (rev 100108)
+++ zope.formlib/trunk/src/zope/formlib/namedtemplate.txt 2009-05-18 20:01:53 UTC (rev 100109)
@@ -1,74 +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.app.pagetemplate import ViewPageTemplateFile
- >>> from zope.formlib.namedtemplate import NamedTemplateImplementation
- >>> sample = ViewPageTemplateFile('sample.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.formlib.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
- >>> from zope.formlib import interfaces
- >>> 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:
-
- >>> from zope import interface
- >>> class MyView:
- ... def __init__(self, context, request):
- ... self.context = context
- ... self.request = request
- ...
- ... __call__ = NamedTemplate('sample2')
-
- >>> sample = ViewPageTemplateFile('sample.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.formlib/trunk/src/zope/formlib/sample.pt
===================================================================
--- zope.formlib/trunk/src/zope/formlib/sample.pt 2009-05-18 20:01:21 UTC (rev 100108)
+++ zope.formlib/trunk/src/zope/formlib/sample.pt 2009-05-18 20:01:53 UTC (rev 100109)
@@ -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>
Modified: zope.formlib/trunk/src/zope/formlib/tests.py
===================================================================
--- zope.formlib/trunk/src/zope/formlib/tests.py 2009-05-18 20:01:21 UTC (rev 100108)
+++ zope.formlib/trunk/src/zope/formlib/tests.py 2009-05-18 20:01:53 UTC (rev 100109)
@@ -37,7 +37,7 @@
import zope.formlib.form
import zope.formlib.interfaces
-import zope.formlib.namedtemplate
+import zope.app.pagetemplate.namedtemplate
FormlibLayer = functional.ZCMLLayer(
os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
@@ -58,7 +58,7 @@
)
@zope.component.adapter(zope.formlib.interfaces.IForm)
- at zope.formlib.namedtemplate.NamedTemplateImplementation
+ at zope.app.pagetemplate.namedtemplate.NamedTemplateImplementation
def TestTemplate(self):
status = self.status
if status:
@@ -329,7 +329,7 @@
>>> errors = zope.formlib.form.getWidgetsData(widgets, 'form', {'summary':'value'})
>>> errors #doctest: +ELLIPSIS
[<zope.app.form.interfaces.WidgetInputError instance at ...>]
-
+
"""
def test_form_template_i18n():
@@ -373,7 +373,7 @@
... <body metal:define-slot="body" />
... </html>
... ''')
-
+
We also need to provide a traversal adapter for the view namespace
that lets us look up the macros.
@@ -550,10 +550,6 @@
setUp=formSetUp, tearDown=zope.component.testing.tearDown,
checker=checker
),
- doctest.DocFileSuite(
- 'namedtemplate.txt',
- setUp=pageSetUp, tearDown=zope.component.testing.tearDown,
- ),
doctest.DocTestSuite(
'zope.formlib.errors'),
errors,
More information about the Zope3-Checkins
mailing list