Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
705edbea
Commit
705edbea
authored
Jul 29, 2007
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Freed viewlets from their Acquisition chains
parent
223b6c6e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
18 deletions
+13
-18
lib/python/Products/Five/viewlet/README.txt
lib/python/Products/Five/viewlet/README.txt
+8
-9
lib/python/Products/Five/viewlet/manager.py
lib/python/Products/Five/viewlet/manager.py
+2
-4
lib/python/Products/Five/viewlet/viewlet.py
lib/python/Products/Five/viewlet/viewlet.py
+3
-5
No files found.
lib/python/Products/Five/viewlet/README.txt
View file @
705edbea
...
...
@@ -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 IBrowserView
>>> from Acquisition import Explicit
>>> class WeatherBox(Explicit):
>>> class WeatherBox(object):
... zope.interface.implements(interfaces.IViewlet)
...
... def __init__(self, context, request, view, manager):
...
...
@@ -109,7 +108,7 @@ But now we register some viewlets for the manager
... IBrowserView, ILeftColumn),
... interfaces.IViewlet, name='weather')
>>> class SportBox(
Explici
t):
>>> class SportBox(
objec
t):
... zope.interface.implements(interfaces.IViewlet)
...
... def __init__(self, context, request, view, manager):
...
...
@@ -311,7 +310,7 @@ The same is true if the specified attribute does not exist:
>>> foo.render()
Traceback (most recent call last):
...
AttributeError:
bar
AttributeError:
'FooViewlet' object has no attribute 'bar'
To create simple template-based viewlets you can use the
``SimpleViewletClass()`` function. This function is very similar to its view
...
...
@@ -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
absolute URL for it:
>>> class JSResource(
Explici
t):
>>> class JSResource(
objec
t):
... def __init__(self, request):
... self.request = request
...
...
...
@@ -381,7 +380,7 @@ absolute URL for it:
The same works for the CSS resource viewlet:
>>> class CSSResource(
Explici
t):
>>> class CSSResource(
objec
t):
... def __init__(self, request):
... self.request = request
...
...
...
@@ -487,7 +486,7 @@ different item:
>>> shownColumns = []
>>> class ContentsViewletManager(
Explici
t):
>>> class ContentsViewletManager(
objec
t):
... zope.interface.implements(interfaces.IViewletManager)
... index = None
...
...
...
@@ -562,7 +561,7 @@ The Viewlets and the Final Result
Now let's create a first viewlet for the manager...
>>> class NameViewlet(
Explici
t):
>>> class NameViewlet(
objec
t):
...
... def __init__(self, context, request, view, manager):
... self.__parent__ = view
...
...
@@ -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
us:
>>> class SizeViewlet(
Explici
t):
>>> class SizeViewlet(
objec
t):
...
... def __init__(self, context, request, view, manager):
... self.__parent__ = view
...
...
lib/python/Products/Five/viewlet/manager.py
View file @
705edbea
...
...
@@ -15,7 +15,7 @@
$Id$
"""
import
Acquisition
from
Acquisition
import
aq_base
from
AccessControl.ZopeGuards
import
guarded_hasattr
import
zope.interface
import
zope.security
...
...
@@ -24,9 +24,7 @@ from zope.viewlet.manager import ViewletManagerBase as origManagerBase
from
Products.Five.browser.pagetemplatefile
import
ZopeTwoPageTemplateFile
aq_base
=
Acquisition
.
aq_base
class
ViewletManagerBase
(
origManagerBase
,
Acquisition
.
Explicit
):
class
ViewletManagerBase
(
origManagerBase
):
"""A base class for Viewlet managers to work in Zope2"""
def
__getitem__
(
self
,
name
):
...
...
lib/python/Products/Five/viewlet/viewlet.py
View file @
705edbea
...
...
@@ -16,16 +16,14 @@
$Id$
"""
import
os
from
Acquisition
import
Explicit
from
zope.viewlet
import
viewlet
as
orig_viewlet
from
Products.Five.browser.pagetemplatefile
import
ZopeTwoPageTemplateFile
# We add Acquisition to all the base classes to enable security machinery
class
ViewletBase
(
orig_viewlet
.
ViewletBase
,
Explicit
):
class
ViewletBase
(
orig_viewlet
.
ViewletBase
):
pass
class
SimpleAttributeViewlet
(
orig_viewlet
.
SimpleAttributeViewlet
,
Explicit
):
class
SimpleAttributeViewlet
(
orig_viewlet
.
SimpleAttributeViewlet
):
pass
class
simple
(
orig_viewlet
.
simple
):
...
...
@@ -52,7 +50,7 @@ def SimpleViewletClass(template, bases=(), attributes=None,
return
class_
class
ResourceViewletBase
(
orig_viewlet
.
ResourceViewletBase
,
Explicit
):
class
ResourceViewletBase
(
orig_viewlet
.
ResourceViewletBase
):
pass
def
JavaScriptViewlet
(
path
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment