Skip to content

Commit

Permalink
add the available() method on viewlets, check for by the viewlet manager
Browse files Browse the repository at this point in the history
  • Loading branch information
janwijbrand committed Jun 27, 2011
1 parent ea094d0 commit 9e2d1dc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CHANGES.txt
Expand Up @@ -4,8 +4,10 @@ Changes
1.9 (unreleased)
----------------

- Nothing changed yet.

- Introduce the `available()` method on viewlet component. The viewlet
manager will filter out unavailable viewlet by calling this method. The
`available()` method is called *after* the viewlet's `update()` is called,
but *before* the `render()` is called.

1.8 (2010-12-16)
----------------
Expand Down
14 changes: 14 additions & 0 deletions src/grokcore/viewlet/components.py
Expand Up @@ -73,6 +73,12 @@ def default_namespace(self):
def namespace(self):
return {}

def update(self):
super(ViewletManager, self).update()
# Filter out the unavailable viewlets *after* the viewlet's update()
# has been called.
self.viewlets = filter(lambda v: v.available(), self.viewlets)

def render(self):
"""See zope.contentprovider.interfaces.IContentProvider"""
# Now render the view
Expand Down Expand Up @@ -115,5 +121,13 @@ def namespace(self):
def update(self):
pass

def available(self):
"""Return True if this viewlet is to be rendered. False otherwise.
Note that the available() method is called *after* update() but
*before* render() but has been called.
"""
return True

def render(self):
return self.template.render(self)
1 change: 1 addition & 0 deletions src/grokcore/viewlet/ftesting.zcml
Expand Up @@ -25,6 +25,7 @@
<include package="zope.annotation" />
<include package="zope.principalregistry" />
<include package="zope.contentprovider" />
<include package="zope.publisher" />
<include package="zope.app.appsetup" />
<include package="zope.app.publication" />
<include package="grokcore.viewlet" />
Expand Down
@@ -0,0 +1 @@
<span tal:replace="provider:bones" />

0 comments on commit 9e2d1dc

Please sign in to comment.