Commit 705edbea authored by Hanno Schlichting's avatar Hanno Schlichting

Freed viewlets from their Acquisition chains

parent 223b6c6e
...@@ -89,8 +89,7 @@ But now we register some viewlets for the manager ...@@ -89,8 +89,7 @@ But now we register some viewlets for the manager
>>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
>>> from zope.publisher.interfaces.browser import IBrowserView >>> from zope.publisher.interfaces.browser import IBrowserView
>>> from Acquisition import Explicit >>> class WeatherBox(object):
>>> class WeatherBox(Explicit):
... zope.interface.implements(interfaces.IViewlet) ... zope.interface.implements(interfaces.IViewlet)
... ...
... def __init__(self, context, request, view, manager): ... def __init__(self, context, request, view, manager):
...@@ -109,7 +108,7 @@ But now we register some viewlets for the manager ...@@ -109,7 +108,7 @@ But now we register some viewlets for the manager
... IBrowserView, ILeftColumn), ... IBrowserView, ILeftColumn),
... interfaces.IViewlet, name='weather') ... interfaces.IViewlet, name='weather')
>>> class SportBox(Explicit): >>> class SportBox(object):
... zope.interface.implements(interfaces.IViewlet) ... zope.interface.implements(interfaces.IViewlet)
... ...
... def __init__(self, context, request, view, manager): ... def __init__(self, context, request, view, manager):
...@@ -311,7 +310,7 @@ The same is true if the specified attribute does not exist: ...@@ -311,7 +310,7 @@ The same is true if the specified attribute does not exist:
>>> foo.render() >>> foo.render()
Traceback (most recent call last): Traceback (most recent call last):
... ...
AttributeError: bar AttributeError: 'FooViewlet' object has no attribute 'bar'
To create simple template-based viewlets you can use the To create simple template-based viewlets you can use the
``SimpleViewletClass()`` function. This function is very similar to its view ``SimpleViewletClass()`` function. This function is very similar to its view
...@@ -365,7 +364,7 @@ fully demonstrate the functionality of the base classes as well. ...@@ -365,7 +364,7 @@ fully demonstrate the functionality of the base classes as well.
The viewlet will look up the resource it was given and tries to produce the The viewlet will look up the resource it was given and tries to produce the
absolute URL for it: absolute URL for it:
>>> class JSResource(Explicit): >>> class JSResource(object):
... def __init__(self, request): ... def __init__(self, request):
... self.request = request ... self.request = request
... ...
...@@ -381,7 +380,7 @@ absolute URL for it: ...@@ -381,7 +380,7 @@ absolute URL for it:
The same works for the CSS resource viewlet: The same works for the CSS resource viewlet:
>>> class CSSResource(Explicit): >>> class CSSResource(object):
... def __init__(self, request): ... def __init__(self, request):
... self.request = request ... self.request = request
... ...
...@@ -487,7 +486,7 @@ different item: ...@@ -487,7 +486,7 @@ different item:
>>> shownColumns = [] >>> shownColumns = []
>>> class ContentsViewletManager(Explicit): >>> class ContentsViewletManager(object):
... zope.interface.implements(interfaces.IViewletManager) ... zope.interface.implements(interfaces.IViewletManager)
... index = None ... index = None
... ...
...@@ -562,7 +561,7 @@ The Viewlets and the Final Result ...@@ -562,7 +561,7 @@ The Viewlets and the Final Result
Now let's create a first viewlet for the manager... Now let's create a first viewlet for the manager...
>>> class NameViewlet(Explicit): >>> class NameViewlet(object):
... ...
... def __init__(self, context, request, view, manager): ... def __init__(self, context, request, view, manager):
... self.__parent__ = view ... self.__parent__ = view
...@@ -635,7 +634,7 @@ that we want to see the name as a column in the table: ...@@ -635,7 +634,7 @@ that we want to see the name as a column in the table:
Let's now write a second viewlet that will display the size of the object for Let's now write a second viewlet that will display the size of the object for
us: us:
>>> class SizeViewlet(Explicit): >>> class SizeViewlet(object):
... ...
... def __init__(self, context, request, view, manager): ... def __init__(self, context, request, view, manager):
... self.__parent__ = view ... self.__parent__ = view
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
$Id$ $Id$
""" """
import Acquisition from Acquisition import aq_base
from AccessControl.ZopeGuards import guarded_hasattr from AccessControl.ZopeGuards import guarded_hasattr
import zope.interface import zope.interface
import zope.security import zope.security
...@@ -24,9 +24,7 @@ from zope.viewlet.manager import ViewletManagerBase as origManagerBase ...@@ -24,9 +24,7 @@ from zope.viewlet.manager import ViewletManagerBase as origManagerBase
from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
aq_base = Acquisition.aq_base class ViewletManagerBase(origManagerBase):
class ViewletManagerBase(origManagerBase, Acquisition.Explicit):
"""A base class for Viewlet managers to work in Zope2""" """A base class for Viewlet managers to work in Zope2"""
def __getitem__(self, name): def __getitem__(self, name):
......
...@@ -16,16 +16,14 @@ ...@@ -16,16 +16,14 @@
$Id$ $Id$
""" """
import os import os
from Acquisition import Explicit
from zope.viewlet import viewlet as orig_viewlet from zope.viewlet import viewlet as orig_viewlet
from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
# We add Acquisition to all the base classes to enable security machinery class ViewletBase(orig_viewlet.ViewletBase):
class ViewletBase(orig_viewlet.ViewletBase, Explicit):
pass pass
class SimpleAttributeViewlet(orig_viewlet.SimpleAttributeViewlet, Explicit): class SimpleAttributeViewlet(orig_viewlet.SimpleAttributeViewlet):
pass pass
class simple(orig_viewlet.simple): class simple(orig_viewlet.simple):
...@@ -52,7 +50,7 @@ def SimpleViewletClass(template, bases=(), attributes=None, ...@@ -52,7 +50,7 @@ def SimpleViewletClass(template, bases=(), attributes=None,
return class_ return class_
class ResourceViewletBase(orig_viewlet.ResourceViewletBase, Explicit): class ResourceViewletBase(orig_viewlet.ResourceViewletBase):
pass pass
def JavaScriptViewlet(path): def JavaScriptViewlet(path):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment