Re: Conditionally render viewlet
Antonin AMAND <[email protected]> Wed, 8 Jun 2011 12:43:11 +0200
| Newsgroups | gmane.comp.web.zope.silva.devel |
|---|---|
| Message-ID | <BANLkTi=-FdJCyrZWWFxM49_ur50m0Mvkui_xU_z50+87ooskmQ@mail.gmail.com> |
>> The viewlet still rendered even though theres no index_left.
>> Then I checked the documentation here
>> http://pypi.python.org/pypi/zope.viewlet, specifically the
>> 'ConditionalViewletManager' section where it states that Viewlets have
>> an 'available' attribute (not a method), so I tried setting available
>> = False, but still the viewlet rendered.
You're right, Viewlet have no available method, I've been mistaken.
What we usually do is this:
In the viewlet manager we override the filters method :
class MyViewletManager(...):
...
def filter(self):
viewlets = super(MyViewletManager, self).filter()
return [v for v in viewlets if v.available()]
Then define an available method on all viewlets of this ViewletManager.
BTW, be carefull with hasattr(self.context, 'index_left'), it checks
with acquisition.
Antonin