[Zope3-checkins] SVN: Zope3/branches/roger-contentprovider/src/zope/viewlet/ Split viewlet package into contentprovider and viewlet

Roger Ineichen roger at projekt01.ch
Thu Oct 6 12:50:21 EDT 2005


Log message for revision 38809:
  Split viewlet package into contentprovider and viewlet

Changed:
  D   Zope3/branches/roger-contentprovider/src/zope/viewlet/configure.zcml
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/interfaces.py
  D   Zope3/branches/roger-contentprovider/src/zope/viewlet/manager.py
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py
  D   Zope3/branches/roger-contentprovider/src/zope/viewlet/tales.py
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py
  A   Zope3/branches/roger-contentprovider/src/zope/viewlet/zope.viewlet-meta.zcml

-=-
Deleted: Zope3/branches/roger-contentprovider/src/zope/viewlet/configure.zcml
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/configure.zcml	2005-10-06 16:49:53 UTC (rev 38808)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/configure.zcml	2005-10-06 16:50:21 UTC (rev 38809)
@@ -1,19 +0,0 @@
-<configure
-    xmlns="http://namespaces.zope.org/zope"
-    xmlns:tales="http://namespaces.zope.org/tales"
-    i18n_domain="zope"
-    >
-
-  <interface interface=".interfaces.ITALESViewletsExpression" />
-  <tales:expressiontype
-      name="viewlets"
-      handler=".tales.TALESViewletsExpression"
-      />
-
-  <interface interface=".interfaces.ITALESViewletExpression" />
-  <tales:expressiontype
-      name="viewlet"
-      handler=".tales.TALESViewletExpression"
-      />
-
-</configure>
\ No newline at end of file

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/interfaces.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/interfaces.py	2005-10-06 16:49:53 UTC (rev 38808)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/interfaces.py	2005-10-06 16:50:21 UTC (rev 38809)
@@ -25,20 +25,11 @@
 from zope.app.i18n import ZopeMessageIDFactory as _
 from zope.app.publisher.interfaces.browser import IBrowserView
 
+from zope.contentprovider.interfaces import IContentProvider
 
-class ViewletRegionLookupError(zope.component.ComponentLookupError):
-    """Viewlet 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.
-    """
-
-
-class IViewlet(IBrowserView):
+class IViewlet(IBrowserView, IContentProvider):
     """A piece of content of a page.
 
     Viewlets are objects that can fill the region specified in a page, most
@@ -59,57 +50,28 @@
         default=0)
 
 
-class IViewletManager(zope.interface.Interface):
-    """An object that provides access to the viewlets.
-
-    The viewlets are of a particular context, request and view configuration
-    are accessible via a particular manager instance. Viewlets are looked up
-    by the region they appear in and the name of the viewlet.
-    """
-
-    context = zope.interface.Attribute(
-        'The context of the view the viewlet appears in.')
-
-    view = zope.interface.Attribute(
-        'The view the viewlet is used in.')
-
-    request = zope.interface.Attribute(
-        'The request of the view the viewlet is used in.')
-
-    def getViewlets(region):
-        """Get all available viewlets of the given region.
-
-        This method is responsible for sorting the viewlets as well.
-        """
-
-    def getViewlet(self, name, region):
-        """Get a particular viewlet of a region selected by name."""
-
-
-class ITALESViewletsExpression(interfaces.ITALESExpression):
-    """TAL namespace for getting a list of viewlets.
-
-    To call viewlets in a view use the the following syntax in a page
-    template::
-
-      <tal:block repeat="viewlet viewlets:path.to.my.IRegion">
-        <tal:block replace="structure viewlet" />
-      </tal:block>
-
-    where ``path.to.my.IRegion`` is a region object that provides
-    ``viewlet.interfaces.IRegion``.
-    """
-
-
-class ITALESViewletExpression(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
-    template::
-
-      <tal:block replace="structure viewlet:path.to.my.IRegion/name" />
-
-    where ``path.to.my.IRegion`` is a region object that provides
-    ``viewlet.interfaces.IRegion`` and ``name`` is the name of the page
-    template.
-    """
+#class IViewletManager(zope.interface.Interface):
+#    """An object that provides access to the viewlets.
+#
+#    The viewlets are of a particular context, request and view configuration
+#    are accessible via a particular manager instance. Viewlets are looked up
+#    by the region they appear in and the name of the viewlet.
+#    """
+#
+#    context = zope.interface.Attribute(
+#        'The context of the view the viewlet appears in.')
+#
+#    view = zope.interface.Attribute(
+#        'The view the viewlet is used in.')
+#
+#    request = 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 __getitem__(self, name, region):
+#        """Get a particular viewlet of a region selected by name."""

Deleted: Zope3/branches/roger-contentprovider/src/zope/viewlet/manager.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/manager.py	2005-10-06 16:49:53 UTC (rev 38808)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/manager.py	2005-10-06 16:50:21 UTC (rev 38809)
@@ -1,74 +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 implementation
-
-$Id: metaconfigure.py 38437 2005-09-10 01:59:07Z rogerineichen $
-"""
-__docformat__ = 'restructuredtext'
-
-import zope.component
-import zope.interface
-import zope.security
-
-from zope.app.viewlet import interfaces
-
-
-class DefaultViewletManager(object):
-    """The Default Viewlet 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
-    context of this request will also be filtered.
-    """
-    zope.interface.implements(interfaces.IViewletManager)
-
-    def __init__(self, context, request, view):
-        self.context = context
-        self.request = request
-        self.view = view
-
-
-    def getViewlets(self, region):
-        """See zope.app.viewlet.interfaces.IViewletManager"""
-        # Find all viewlets for this region
-        viewlets = zope.component.getAdapters(
-            (self.context, self.request, self.view), region)
-        # Sort out all viewlets that cannot be accessed by the principal
-        viewlets = [viewlet for name, viewlet in viewlets
-                    if zope.security.canAccess(viewlet, '__call__')]
-        # Sort the viewlets by weight.
-        viewlets.sort(lambda x, y: cmp(x.weight, y.weight))
-
-        return viewlets
-
-
-    def getViewlet(self, name, region):
-        """See zope.app.viewlet.interfaces.IViewletManager"""
-        # Find the viewlet
-        viewlet = zope.component.queryMultiAdapter(
-            (self.context, self.request, self.view), region, name=name)
-
-        # If the viewlet was not found, then raise a lookup error
-        if viewlet is None:
-            raise zope.component.interfaces.ComponentLookupError(
-                'No viewlet with name `%s` found.' %name)
-
-        # If the viewlet cannot be accessed, then raise an unauthorized error
-        if not zope.security.canAccess(viewlet, '__call__'):
-            raise zope.security.interfaces.Unauthorized(
-                'You are not authorized to access the viewlet '
-                'called `%s`.' %name)
-
-        # Return the rendered viewlet.
-        return viewlet

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py	2005-10-06 16:49:53 UTC (rev 38808)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py	2005-10-06 16:50:21 UTC (rev 38809)
@@ -30,7 +30,9 @@
 from zope.app.publisher.browser import viewmeta
 from zope.app.publisher.interfaces.browser import IBrowserView
 
-from zope.app.viewlet import viewlet, interfaces
+from zope.contentprovider import interfaces
+from zope.viewlet import viewlet
+from zope.viewlet import interfaces
 
 
 def viewletDirective(_context, name, permission, region,

Deleted: Zope3/branches/roger-contentprovider/src/zope/viewlet/tales.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/tales.py	2005-10-06 16:49:53 UTC (rev 38808)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/tales.py	2005-10-06 16:50:21 UTC (rev 38809)
@@ -1,114 +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 tales expression registrations
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-import zope.interface
-import zope.component
-from zope.tales import expressions
-
-from zope.app.viewlet import interfaces, manager
-
-
-def getRegion(str):
-    """Get a region from the string.
-
-    This function will create the dummy region implementation as well.
-    """
-    region = zope.component.queryUtility(interfaces.IRegion, name=str)
-    if region is None:
-        raise interfaces.ViewletRegionLookupError(
-            'Viewlet region interface not found.', str)
-    return region
-
-
-def getRegionFieldData(region, context):
-    """Get a dictionary of values for the region fields."""
-    data = {}
-    for name, field in zope.schema.getFields(region).items():
-        data[name] = context.vars.get(name, field.default)
-    return data
-
-
-class TALESViewletsExpression(expressions.StringExpr):
-    """Collect viewlets via a TAL namespace called `viewlets`."""
-
-    zope.interface.implements(interfaces.ITALESViewletsExpression)
-
-    def __call__(self, econtext):
-        context = econtext.vars['context']
-        request = econtext.vars['request']
-        view = econtext.vars['view']
-
-        # get the region from the expression
-        region = getRegion(self._s)
-
-        # Find the viewlets
-        viewletManager = zope.component.queryMultiAdapter(
-            (context, request, view), interfaces.IViewletManager)
-        if viewletManager is None:
-            viewletManager = manager.DefaultViewletManager(
-                context, request, view)
-
-        viewlets = viewletManager.getViewlets(region)
-
-        # Insert the data gotten from the context
-        data = getRegionFieldData(region, econtext)
-        for viewlet in viewlets:
-            viewlet.__dict__.update(data)
-
-        return viewlets
-
-
-class TALESViewletExpression(expressions.StringExpr):
-    """Collects a single viewlet via a TAL namespace called viewlet."""
-
-    zope.interface.implements(interfaces.ITALESViewletExpression)
-
-    def __init__(self, name, expr, engine):
-        if not '/' in expr:
-            raise KeyError('Use `iface/viewletname` for defining the viewlet.')
-
-        parts = expr.split('/')
-        if len(parts) > 2:
-            raise KeyError("Do not use more then one / for defining iface/key.")
-
-        # get interface from key
-        self._iface = parts[0]
-        self._name = parts[1]
-
-    def __call__(self, econtext):
-        context = econtext.vars['context']
-        request = econtext.vars['request']
-        view = econtext.vars['view']
-
-        # get the region from the expression
-        region = getRegion(self._iface)
-
-        # Find the viewlets
-        viewletManager = zope.component.queryMultiAdapter(
-            (context, request, view), interfaces.IViewletManager)
-        if viewletManager is None:
-            viewletManager = manager.DefaultViewletManager(
-                context, request, view)
-
-        viewlet = viewletManager.getViewlet(self._name, region)
-
-        # Insert the data gotten from the context
-        data = getRegionFieldData(region, econtext)
-        viewlet.__dict__.update(data)
-
-        return viewlet()

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py	2005-10-06 16:49:53 UTC (rev 38808)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/viewlet.py	2005-10-06 16:50:21 UTC (rev 38809)
@@ -23,7 +23,7 @@
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 from zope.app.publisher.browser import BrowserView
 
-from zope.app.viewlet import interfaces
+from zope.viewlet import interfaces
 
 
 class ViewletPageTemplateFile(ViewPageTemplateFile):

Copied: Zope3/branches/roger-contentprovider/src/zope/viewlet/zope.viewlet-meta.zcml (from rev 38802, Zope3/branches/roger-contentprovider/src/zope/viewlet/zope.app.viewlet-meta.zcml)
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/zope.app.viewlet-meta.zcml	2005-10-06 16:25:11 UTC (rev 38802)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/zope.viewlet-meta.zcml	2005-10-06 16:50:21 UTC (rev 38809)
@@ -0,0 +1 @@
+<include package="zope.viewlet" file="meta.zcml" />



More information about the Zope3-Checkins mailing list