[Zope3-checkins]
SVN: Zope3/branches/roger-contentprovider/src/zope/contentprovider/
Split viewlet package into contentprovider and viewlet
Roger Ineichen
roger at projekt01.ch
Thu Oct 6 12:49:54 EDT 2005
Log message for revision 38808:
Split viewlet package into contentprovider and viewlet
Changed:
U Zope3/branches/roger-contentprovider/src/zope/contentprovider/configure.zcml
D Zope3/branches/roger-contentprovider/src/zope/contentprovider/directives.txt
U Zope3/branches/roger-contentprovider/src/zope/contentprovider/interfaces.py
U Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py
D Zope3/branches/roger-contentprovider/src/zope/contentprovider/meta.zcml
D Zope3/branches/roger-contentprovider/src/zope/contentprovider/metaconfigure.py
D Zope3/branches/roger-contentprovider/src/zope/contentprovider/metadirectives.py
U Zope3/branches/roger-contentprovider/src/zope/contentprovider/tales.py
-=-
Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/configure.zcml
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/configure.zcml 2005-10-06 16:41:41 UTC (rev 38807)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/configure.zcml 2005-10-06 16:49:53 UTC (rev 38808)
@@ -1,19 +1,18 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:tales="http://namespaces.zope.org/tales"
- i18n_domain="zope"
- >
+ i18n_domain="zope">
- <interface interface=".interfaces.ITALESViewletsExpression" />
+ <interface interface=".interfaces.ITALESProvidersExpression" />
<tales:expressiontype
- name="viewlets"
- handler=".tales.TALESViewletsExpression"
+ name="providers"
+ handler=".tales.TALESProviderExpression"
/>
- <interface interface=".interfaces.ITALESViewletExpression" />
+ <interface interface=".interfaces.ITALESProviderExpression" />
<tales:expressiontype
- name="viewlet"
- handler=".tales.TALESViewletExpression"
+ name="provider"
+ handler=".tales.TALESProviderExpression"
/>
</configure>
\ No newline at end of file
Deleted: Zope3/branches/roger-contentprovider/src/zope/contentprovider/directives.txt
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/directives.txt 2005-10-06 16:41:41 UTC (rev 38807)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/directives.txt 2005-10-06 16:49:53 UTC (rev 38808)
@@ -1,183 +0,0 @@
-=========================
-The ``viewlet`` Directive
-=========================
-
-The viewlet directive allows you to quickly register a new paglet without much
-hassle, like it was shown in the `README.txt` file. Here is a sample
-directive::
-
- >>> from zope.configuration import xmlconfig
- >>> context = xmlconfig.string('''
- ... <configure i18n_domain="zope">
- ... <include package="zope.app.viewlet" file="meta.zcml" />
- ... </configure>
- ... ''')
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.viewlet.tests">
- ... <viewlet
- ... name="testviewlet"
- ... for="*"
- ... region=".test_doc.ITestRegion"
- ... template="test_viewlet.pt"
- ... permission="zope.Public"
- ... />
- ... </configure>
- ... ''', context=context)
-
-As you can see, the directive looks very similar to the page directive and you
-are right. The viewlet directive does not permit you to specify a `menu` and
-`title`, since it is not sensible to have a menu item for a viewlet. However,
-it does support two more qualifying attributes, `view` and `region`. While view
-is nearly never specified (very common default), the `region` attribute *must*
-be specified. An optional `weight` attribute (not shown above) allows you to
-change the position of a particular viewlet relative to the others. The
-default value is zero.
-
-If we now look into the adapter registry, we will find the viewlet:
-
- >>> class Content(object):
- ... pass
- >>> content = Content()
-
- >>> from zope.publisher.browser import TestRequest
- >>> request = TestRequest()
-
- >>> from zope.app.publisher.browser import BrowserView
- >>> view = BrowserView(content, request)
-
- >>> import zope.interface
- >>> from zope.app.viewlet.tests.test_doc import ITestRegion
-
- >>> import zope.component
- >>> from zope.app.viewlet.interfaces import IViewlet
- >>> viewlet = zope.component.getMultiAdapter(
- ... (content, request, view), ITestRegion, name='testviewlet')
- >>> viewlet()
- u'<div>testviewlet macro content</div>\n'
-
-Let's now ensure that we can also specify a viewlet class:
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.viewlet.tests">
- ... <viewlet
- ... name="testviewlet2"
- ... for="*"
- ... region=".test_doc.ITestRegion"
- ... template="test_viewlet.pt"
- ... class=".test_doc.TestViewlet"
- ... permission="zope.Public"
- ... />
- ... </configure>
- ... ''', context=context)
-
- >>> viewlet = zope.component.getMultiAdapter(
- ... (content, request, view), ITestRegion, name='testviewlet2')
- >>> viewlet()
- u'<div>testviewlet macro content</div>\n'
-
-Okay, so the template-driven cases wrok. But just specifying a class should
-also work:
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.viewlet.tests">
- ... <viewlet
- ... name="testviewlet3"
- ... for="*"
- ... region=".test_doc.ITestRegion"
- ... class=".test_doc.TestViewlet2"
- ... permission="zope.Public"
- ... />
- ... </configure>
- ... ''', context=context)
-
- >>> viewlet = zope.component.getMultiAdapter(
- ... (content, request, view), ITestRegion, name='testviewlet3')
- >>> viewlet()
- u'called'
-
-It should also be possible to specify an alternative attribute of the class to
-be rendered upon calling the viewlet:
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.viewlet.tests">
- ... <viewlet
- ... name="testviewlet4"
- ... for="*"
- ... region=".test_doc.ITestRegion"
- ... class=".test_doc.TestViewlet"
- ... attribute="doSomething"
- ... permission="zope.Public"
- ... />
- ... </configure>
- ... ''', context=context)
-
- >>> viewlet = zope.component.getMultiAdapter(
- ... (content, request, view), ITestRegion, name='testviewlet4')
- >>> viewlet()
- u'something'
-
-
-Error Scenarios
----------------
-
-Neither the class or template have been specified:
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.viewlet.tests">
- ... <viewlet
- ... name="testviewlet"
- ... region=".test_doc.ITestRegion"
- ... permission="zope.Public"
- ... />
- ... </configure>
- ... ''', context=context)
- Traceback (most recent call last):
- ...
- ZopeXMLConfigurationError: File "<string>", line 4.2-8.8
- ConfigurationError: Must specify a class or template
-
-The specified attribute is not ``__call__``, but also a template has been
-specified:
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.viewlet.tests">
- ... <viewlet
- ... name="testviewlet"
- ... region=".test_doc.ITestRegion"
- ... template="test_viewlet.pt"
- ... attribute="faux"
- ... permission="zope.Public"
- ... />
- ... </configure>
- ... ''', context=context)
- Traceback (most recent call last):
- ...
- ZopeXMLConfigurationError: File "<string>", line 4.2-10.8
- ConfigurationError: Attribute and template cannot be used together.
-
-Now, we are not specifying a template, but a class that does not have the
-specified attribute:
-
- >>> context = xmlconfig.string('''
- ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.viewlet.tests">
- ... <viewlet
- ... name="testviewlet"
- ... region=".test_doc.ITestRegion"
- ... class=".test_doc.TestViewlet"
- ... attribute="faux"
- ... permission="zope.Public"
- ... />
- ... </configure>
- ... ''', context=context)
- Traceback (most recent call last):
- ...
- ZopeXMLConfigurationError: File "<string>", line 4.2-10.8
- ConfigurationError: The provided class doesn't have the specified attribute
Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/interfaces.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/interfaces.py 2005-10-06 16:41:41 UTC (rev 38807)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/interfaces.py 2005-10-06 16:49:53 UTC (rev 38808)
@@ -26,24 +26,25 @@
from zope.app.publisher.interfaces.browser import IBrowserView
-class ViewletRegionLookupError(zope.component.ComponentLookupError):
- """Viewlet region object not found."""
+class RegionLookupError(zope.component.ComponentLookupError):
+ """Region object not found."""
class IRegion(zope.interface.interfaces.IInterface):
"""Type interface for viewlet regions.
Region interfaces specify the environment variables that are available to
- the viewlet. How those variables are provided is up to the implementation.
+ the IContentProvider. How those variables are provided is up to the
+ implementation.
"""
-class IViewlet(IBrowserView):
+class IContentProvider(IBrowserView):
"""A piece of content of a page.
- Viewlets are objects that can fill the region specified in a page, most
- often page templates. They are selected by the context, request and
- view. All viewlets of a particular region must also provide the region
+ Content provider are objects that can fill the region specified in a
+ page, most often page templates. They are selected by the context, request
+ and view. All viewlets of a particular region must also provide the region
interface.
"""
@@ -59,7 +60,7 @@
default=0)
-class IViewletManager(zope.interface.Interface):
+class IContentProviderManager(zope.interface.Interface):
"""An object that provides access to the viewlets.
The viewlets are of a particular context, request and view configuration
@@ -76,17 +77,21 @@
request = zope.interface.Attribute(
'The request of the view the viewlet is used in.')
- def getViewlets(region):
+# TODO: implement dummy object providing the region or lookup hook
+# region = zope.interface.Attribute(
+# 'The request of the view the viewlet is used in.')
+
+ def values(region):
"""Get all available viewlets of the given region.
This method is responsible for sorting the viewlets as well.
"""
- def getViewlet(self, name, region):
+ def __getitem__(self, name, region):
"""Get a particular viewlet of a region selected by name."""
-class ITALESViewletsExpression(interfaces.ITALESExpression):
+class ITALESProvidersExpression(interfaces.ITALESExpression):
"""TAL namespace for getting a list of viewlets.
To call viewlets in a view use the the following syntax in a page
@@ -101,7 +106,7 @@
"""
-class ITALESViewletExpression(interfaces.ITALESExpression):
+class ITALESProviderExpression(interfaces.ITALESExpression):
"""TAL namespace for getting a single viewlet.
To call a named viewlet in a view use the the following syntax in a page
Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py 2005-10-06 16:41:41 UTC (rev 38807)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py 2005-10-06 16:49:53 UTC (rev 38808)
@@ -21,11 +21,11 @@
import zope.interface
import zope.security
-from zope.app.viewlet import interfaces
+from zope.viewlet import interfaces
-class DefaultViewletManager(object):
- """The Default Viewlet Manager
+class DefaultContentProviderManager(object):
+ """The Default ContentProvider Manager
This implementation looks up all viewlets from the adapter registry and
sorts the viewlet list by weight. Viewlets that are not accessible in the
@@ -39,7 +39,7 @@
self.view = view
- def getViewlets(self, region):
+ def values(self, region):
"""See zope.app.viewlet.interfaces.IViewletManager"""
# Find all viewlets for this region
viewlets = zope.component.getAdapters(
@@ -53,7 +53,7 @@
return viewlets
- def getViewlet(self, name, region):
+ def __getitem__(self, name, region):
"""See zope.app.viewlet.interfaces.IViewletManager"""
# Find the viewlet
viewlet = zope.component.queryMultiAdapter(
Deleted: Zope3/branches/roger-contentprovider/src/zope/contentprovider/meta.zcml
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/meta.zcml 2005-10-06 16:41:41 UTC (rev 38807)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/meta.zcml 2005-10-06 16:49:53 UTC (rev 38808)
@@ -1,14 +0,0 @@
-<configure
- xmlns:meta="http://namespaces.zope.org/meta">
-
- <meta:directives namespace="http://namespaces.zope.org/browser">
-
- <meta:directive
- name="viewlet"
- schema=".metadirectives.IViewletDirective"
- handler=".metaconfigure.viewletDirective"
- />
-
- </meta:directives>
-
-</configure>
Deleted: Zope3/branches/roger-contentprovider/src/zope/contentprovider/metaconfigure.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/metaconfigure.py 2005-10-06 16:41:41 UTC (rev 38807)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/metaconfigure.py 2005-10-06 16:49:53 UTC (rev 38808)
@@ -1,128 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 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.
-#
-##############################################################################
-"""Viewlet metadconfigure
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-import os
-
-from zope.security import checker
-
-from zope.configuration.exceptions import ConfigurationError
-from zope.interface import Interface, classImplements
-from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-
-from zope.app.component.interface import provideInterface
-from zope.app.component import metaconfigure
-from zope.app.publisher.browser import viewmeta
-from zope.app.publisher.interfaces.browser import IBrowserView
-
-from zope.app.viewlet import viewlet, interfaces
-
-
-def viewletDirective(_context, name, permission, region,
- for_=Interface, layer=IDefaultBrowserLayer,
- view=IBrowserView,
- class_=None, template=None, attribute='__call__', weight=0,
- allowed_interface=None, allowed_attributes=None):
-
- required = {}
-
- # Get the permission; mainly to correctly handle CheckerPublic.
- permission = viewmeta._handle_permission(_context, permission)
-
- # Either the class or template must be specified.
- if not (class_ or template):
- raise ConfigurationError("Must specify a class or template")
-
- # Make sure that all the non-default attribute specifications are correct.
- if attribute != '__call__':
- if template:
- raise ConfigurationError(
- "Attribute and template cannot be used together.")
-
- # Note: The previous logic forbids this condition to evere occur.
- if not class_:
- raise ConfigurationError(
- "A class must be provided if attribute is used")
-
- # Make sure that the template exists and that all low-level API methods
- # have the right permission.
- if template:
- template = os.path.abspath(str(_context.path(template)))
- if not os.path.isfile(template):
- raise ConfigurationError("No such file", template)
- required['__getitem__'] = permission
-
- # Make sure the has the right form, if specified.
- if class_:
- if attribute != '__call__':
- if not hasattr(class_, attribute):
- raise ConfigurationError(
- "The provided class doesn't have the specified attribute "
- )
- if template:
- # Create a new class for the viewlet template and class.
- new_class = viewlet.SimpleViewletClass(
- template, bases=(class_, ), weight=weight)
- else:
- if not hasattr(class_, 'browserDefault'):
- cdict = {
- 'browserDefault':
- lambda self, request: (getattr(self, attribute), ())
- }
- else:
- cdict = {}
-
- cdict['_weight'] = weight
- cdict['__name__'] = name
- cdict['__page_attribute__'] = attribute
- new_class = type(class_.__name__,
- (class_, viewlet.SimpleAttributeViewlet), cdict)
-
- if hasattr(class_, '__implements__'):
- classImplements(new_class, IBrowserPublisher)
-
- else:
- # Create a new class for the viewlet template alone.
- new_class = viewlet.SimpleViewletClass(
- template, name=name, weight=weight)
-
- # Make sure the new class implements the region
- classImplements(new_class, region)
-
- for attr_name in (attribute, 'browserDefault', '__call__',
- 'publishTraverse', 'weight'):
- required[attr_name] = permission
-
- viewmeta._handle_allowed_interface(
- _context, allowed_interface, permission, required)
- viewmeta._handle_allowed_attributes(
- _context, allowed_interface, permission, required)
-
- viewmeta._handle_for(_context, for_)
- metaconfigure.interface(_context, view)
- metaconfigure.interface(_context, region, interfaces.IRegion)
-
- checker.defineChecker(new_class, checker.Checker(required))
-
- # register viewlet
- _context.action(
- discriminator = ('viewlet', for_, layer, view, region, name),
- callable = metaconfigure.handler,
- args = ('provideAdapter',
- (for_, layer, view), region, name, new_class,
- _context.info),)
Deleted: Zope3/branches/roger-contentprovider/src/zope/contentprovider/metadirectives.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/metadirectives.py 2005-10-06 16:41:41 UTC (rev 38807)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/metadirectives.py 2005-10-06 16:49:53 UTC (rev 38808)
@@ -1,50 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 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.
-#
-##############################################################################
-"""Viewlet metadirective
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-from zope.configuration.fields import GlobalInterface
-from zope.schema import Int
-
-from zope.app.publisher.browser import metadirectives
-
-
-class IViewletDirective(metadirectives.IPagesDirective,
- metadirectives.IViewPageSubdirective):
- """A directive to register a new viewlet.
-
- Viewlet registrations are very similar to page registrations, except that
- they are additionally qualified by the region and view they are used for. An
- additional `weight` attribute is specified that is intended to coarsly
- control the order of the viewlets.
- """
-
- region = GlobalInterface(
- title=u"region",
- description=u"The region interface this viewlet is for.",
- required=True)
-
- view = GlobalInterface(
- title=u"view",
- description=u"The interface of the view this viewlet is for. "
- u"(default IBrowserView)""",
- required=False)
-
- weight = Int(
- title=u"weight",
- description=u"Integer key for sorting viewlets in the same region.",
- required=False)
Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/tales.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/tales.py 2005-10-06 16:41:41 UTC (rev 38807)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/tales.py 2005-10-06 16:49:53 UTC (rev 38808)
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Viewlet tales expression registrations
+"""Provider tales expression registrations
$Id$
"""
@@ -43,10 +43,10 @@
return data
-class TALESViewletsExpression(expressions.StringExpr):
- """Collect viewlets via a TAL namespace called `viewlets`."""
+class TALESProvidersExpression(expressions.StringExpr):
+ """Collect content provider via a TAL namespace."""
- zope.interface.implements(interfaces.ITALESViewletsExpression)
+ zope.interface.implements(interfaces.ITALESProvidersExpression)
def __call__(self, econtext):
context = econtext.vars['context']
@@ -73,10 +73,10 @@
return viewlets
-class TALESViewletExpression(expressions.StringExpr):
- """Collects a single viewlet via a TAL namespace called viewlet."""
+class TALESProviderExpression(expressions.StringExpr):
+ """Collects a single content provider via a TAL namespace."""
- zope.interface.implements(interfaces.ITALESViewletExpression)
+ zope.interface.implements(interfaces.ITALESProviderExpression)
def __init__(self, name, expr, engine):
if not '/' in expr:
More information about the Zope3-Checkins
mailing list