Re: Conditionally render viewlet

Andrew Altepeter <[email protected]> Wed, 8 Jun 2011 07:25:48 -0500
Newsgroups gmane.comp.web.zope.silva.devel
Message-ID <[email protected]>
--===============4390400384123977920==
Content-Type: multipart/alternative; boundary=000e0cd56864c0036404a5326f72

--000e0cd56864c0036404a5326f72
Content-Type: text/plain; charset=ISO-8859-1

Hi Jon,

I've gotten around this in my viewlets in this manner:

In the viewlet's update(), I define set a local attribute on the viewlet:

    def update(self):
        self.skip = False
        if self.should_be_skipped():
            self.skip = True

And then in the viewlet's template, I do:

<tal:skip condition="not:viewlet/skip">
  all viewlet html is inside this
</tal:skip>

While not the most efficient, it does get the job done.

Note than with a view/viewlet's template, you can add variables to the
namespace, so in the above example instead of "not:viewlet/skip" you can
just do "not:skip"...

In your viewlet class, define another method:

    def default_namespace(self):
        """add 'skip' to the template's namespace.  This method is called
_after_ update()"""
        namespace = super(MyViewletClass, self).default_namespace()
        namespace['skip'] = self.skip
        return namespace

Cheers,
Andy

On Wed, Jun 8, 2011 at 6:37 AM, Jonathan Bowlas <j.bowlas-hclig2XLE9Zaa/[email protected]> wrote:

> Is there an example infrae extension or theme where the filter method
> is overridden?
>
> J
>
> On 8 June 2011 12:35, Jonathan Bowlas <j.bowlas-hclig2XLE9Zaa/[email protected]> wrote:
> > Sorry but it's still not working, I did this:
> >
> > class LeftColumn(silvaviews.ViewletManager):
> >    """Left Content Area
> >    """
> >    def filter(self):
> >         viewlets = super(LeftColumn, self).filter()
> >         return [v for v in viewlets if v.available()]
> >
> > But it returns this traceback:
> >
> > 2011-06-08 12:30:35,868 ERROR [infrae.wsgi]
> > Error while rendering error message
> > Object class: Products.Silva.Root.Root
> > Object path: /silva
> > Request URL: http://localhost:8080/silva/test/@@index.html
> > Request method: GET
> > User: admin
> > User-agent: Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101
> Firefox/4.0.1
> > Refer: http://localhost:8080/silva/test
> > Traceback (innermost last):
> >  Module infrae.wsgi.publisher, line 183, in error
> >  Module silva.core.views.views, line 73, in __call__
> >  Module infrae.layout.components, line 105, in __call__
> >   - Published class: silva.core.layout.porto.errors.OtherErrorPage
> >   - Object path: /silva
> >   - Object type: Silva Root
> >  Module infrae.layout.components, line 77, in __call__
> >  Module infrae.layout.components, line 70, in render
> >  Module infrae.layout.components, line 67, in _render_template
> >  Module five.grok.components, line 133, in render
> >  Module zope.pagetemplate.pagetemplate, line 113, in pt_render
> >  Module zope.tal.talinterpreter, line 271, in __call__
> >  Module zope.tal.talinterpreter, line 343, in interpret
> >  Module zope.tal.talinterpreter, line 531, in do_optTag_tal
> >  Module zope.tal.talinterpreter, line 513, in no_tag
> >  Module zope.tal.talinterpreter, line 343, in interpret
> >  Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal
> >  Module Products.PageTemplates.Expressions, line 220, in
> evaluateStructure
> >  Module zope.tales.tales, line 696, in evaluate
> >   - URL:
> c:\silva-2.3.1\eggs\silva.core.layout-2.3.2-py2.6.egg\silva\core\layout\porto\porto_templates\
> mainlayout.pt
> >   - Line 29, Column 4
> >   - Expression: <StringExpr u'layout'>
> >   - Names:
> >      {'args': (),
> >       'container': <Root at /silva>,
> >       'context': <Root at /silva>,
> >       'default': <object object at 0x01AD1720>,
> >       'here': <Root at /silva>,
> >       'layout':
> > <silvatheme.uclcorporateidentity.uclcorporateidentity.MainErrorLayout
> > object at 0x0722CE10>,
> >       'loop': {},
> >       'nothing': None,
> >       'options': {},
> >       'repeat': <Products.PageTemplates.Expressions.SafeMapping
> > object at 0x0721D660>,
> >       'request': <WSGIRequest,
> > URL=http://localhost:8080/silva/test/@@index.html>,
> >       'root': <Application at >,
> >       'static': <silva.resourceinclude.resource.ResourceView object
> > at 0x0722C750>,
> >       'template':
> > <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at
> > 0x06364A90>,
> >       'traverse_subpath': [],
> >       'user': <User 'admin'>,
> >       'view': <silva.core.layout.porto.errors.OtherErrorPage object
> > at 0x06A63BF0>,
> >       'views': <Products.Five.browser.pagetemplatefile.ViewMapper
> > object at 0x0723A6D0>}
> >  Module zope.contentprovider.tales, line 80, in __call__
> >  Module grokcore.viewlet.components, line 80, in render
> >  Module five.grok.components, line 133, in render
> >  Module zope.pagetemplate.pagetemplate, line 113, in pt_render
> >  Module zope.tal.talinterpreter, line 271, in __call__
> >  Module zope.tal.talinterpreter, line 343, in interpret
> >  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
> >  Module zope.tal.talinterpreter, line 518, in do_optTag
> >  Module zope.tal.talinterpreter, line 513, in no_tag
> >  Module zope.tal.talinterpreter, line 343, in interpret
> >  Module zope.tal.talinterpreter, line 852, in do_condition
> >  Module zope.tal.talinterpreter, line 343, in interpret
> >  Module zope.tal.talinterpreter, line 531, in do_optTag_tal
> >  Module zope.tal.talinterpreter, line 513, in no_tag
> >  Module zope.tal.talinterpreter, line 343, in interpret
> >  Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal
> >  Module Products.PageTemplates.Expressions, line 220, in
> evaluateStructure
> >  Module zope.tales.tales, line 696, in evaluate
> >   - URL:
> c:\silva-2.3.1\src\silvatheme.uclcorporateidentity\silvatheme\uclcorporateidentity\uclcorporateidentity_templates\
> layout.pt
> >   - Line 5, Column 8
> >   - Expression: <StringExpr u'threecolumn'>
> >   - Names:
> >      {'args': (),
> >       'container': <Root at /silva>,
> >       'context': <Root at /silva>,
> >       'default': <object object at 0x01AD1720>,
> >       'here': <Root at /silva>,
> >       'layout':
> > <silvatheme.uclcorporateidentity.uclcorporateidentity.MainErrorLayout
> > object at 0x0722CE10>,
> >       'loop': {},
> >       'nothing': None,
> >       'options': {},
> >       'provider':
> > <silvatheme.uclcorporateidentity.uclcorporateidentity.Layout object at
> > 0x072033F0>,
> >       'repeat': <Products.PageTemplates.Expressions.SafeMapping
> > object at 0x0721D690>,
> >       'request': <WSGIRequest,
> > URL=http://localhost:8080/silva/test/@@index.html>,
> >       'root': <Application at >,
> >       'static': <silva.resourceinclude.resource.ResourceView object
> > at 0x07234D30>,
> >       'template':
> > <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at
> > 0x063EF510>,
> >       'traverse_subpath': [],
> >       'user': <User 'admin'>,
> >       'view': <silva.core.layout.porto.errors.OtherErrorPage object
> > at 0x06A63BF0>,
> >       'viewletmanager':
> > <silvatheme.uclcorporateidentity.uclcorporateidentity.Layout object at
> > 0x072033F0>,
> >       'views': <Products.Five.browser.pagetemplatefile.ViewMapper
> > object at 0x07234DB0>}
> >  Module zope.contentprovider.tales, line 80, in __call__
> >  Module grokcore.viewlet.components, line 80, in render
> >  Module five.grok.components, line 133, in render
> >  Module zope.pagetemplate.pagetemplate, line 113, in pt_render
> >  Module zope.tal.talinterpreter, line 271, in __call__
> >  Module zope.tal.talinterpreter, line 343, in interpret
> >  Module zope.tal.talinterpreter, line 531, in do_optTag_tal
> >  Module zope.tal.talinterpreter, line 513, in no_tag
> >  Module zope.tal.talinterpreter, line 343, in interpret
> >  Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal
> >  Module Products.PageTemplates.Expressions, line 220, in
> evaluateStructure
> >  Module zope.tales.tales, line 696, in evaluate
> >   - URL:
> c:\silva-2.3.1\src\silvatheme.uclcorporateidentity\silvatheme\uclcorporateidentity\uclcorporateidentity_templates\
> threecolumn.pt
> >   - Line 6, Column 12
> >   - Expression: <StringExpr u'leftcolumn'>
> >   - Names:
> >      {'args': (),
> >       'container': <Root at /silva>,
> >       'context': <Root at /silva>,
> >       'default': <object object at 0x01AD1720>,
> >       'here': <Root at /silva>,
> >       'layout':
> > <silvatheme.uclcorporateidentity.uclcorporateidentity.MainErrorLayout
> > object at 0x0722CE10>,
> >       'loop': {},
> >       'nothing': None,
> >       'options': {},
> >       'provider':
> > <silvatheme.uclcorporateidentity.uclcorporateidentity.ThreeColumn
> > object at 0x07234ED0>,
> >       'repeat': <Products.PageTemplates.Expressions.SafeMapping
> > object at 0x0721D6F0>,
> >       'request': <WSGIRequest,
> > URL=http://localhost:8080/silva/test/@@index.html>,
> >       'root': <Application at >,
> >       'static': <silva.resourceinclude.resource.ResourceView object
> > at 0x07234F30>,
> >       'template':
> > <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at
> > 0x063EF7D0>,
> >       'traverse_subpath': [],
> >       'user': <User 'admin'>,
> >       'view': <silva.core.layout.porto.errors.OtherErrorPage object
> > at 0x06A63BF0>,
> >       'viewletmanager':
> > <silvatheme.uclcorporateidentity.uclcorporateidentity.ThreeColumn
> > object at 0x07234ED0>,
> >       'views': <Products.Five.browser.pagetemplatefile.ViewMapper
> > object at 0x07234F50>}
> >  Module zope.contentprovider.tales, line 77, in __call__
> >  Module zope.viewlet.manager, line 104, in update
> > TypeError: filter() takes exactly 1 argument (2 given)
> >
> > Any Ideas?
> >
> >
> > On 8 June 2011 11:43, Antonin AMAND <[email protected]> wrote:
> >>>> 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
> >> _______________________________________________
> >> silva-dev mailing list
> >> silva-dev-IAPFreCvJWM6s/[email protected]
> >> https://lists.infrae.com/mailman/listinfo/silva-dev
> >>
> >
> >
> >
> > --
> > Jonathan Bowlas
> > Web Support Officer
> > Media Services
> > University College London
> > Email: j.bowlas-hclig2XLE9Zaa/[email protected]
> >
>
>
>
> --
> Jonathan Bowlas
> Web Support Officer
> Media Services
> University College London
> Email: j.bowlas-hclig2XLE9Zaa/[email protected]
> _______________________________________________
> silva-dev mailing list
> silva-dev-IAPFreCvJWM6s/[email protected]
> https://lists.infrae.com/mailman/listinfo/silva-dev
>

--000e0cd56864c0036404a5326f72
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Jon,<div><br></div><div>I&#39;ve gotten around this in my viewlets in th=
is manner:</div><div><br></div><div>In the viewlet&#39;s update(), I define=
 set a local attribute on the viewlet:</div><div><br></div><div><div>=A0=A0=
 =A0def update(self):</div>
<div>=A0=A0 =A0 =A0 =A0self.skip =3D False</div><div>=A0=A0 =A0 =A0 =A0if s=
elf.should_be_skipped():</div><div>=A0=A0 =A0 =A0 =A0 =A0 =A0self.skip =3D =
True</div><div><br></div><div>And then in the viewlet&#39;s template, I do:=
</div><div><br></div><div>&lt;tal:skip condition=3D&quot;not:viewlet/skip&q=
uot;&gt;</div>
<div>=A0=A0all viewlet html is inside this</div><div>&lt;/tal:skip&gt;</div=
><div><br></div><div>While not the most efficient, it does get the job done=
.</div><div><br></div><div>Note than with a view/viewlet&#39;s template, yo=
u can add variables to the namespace, so in the above example instead of &q=
uot;not:viewlet/skip&quot; you can just do &quot;not:skip&quot;...</div>
<div><br></div><div>In your viewlet class, define another method:</div><div=
><br></div><div><div>=A0=A0 =A0def default_namespace(self):</div><div>=A0=
=A0 =A0 =A0 =A0&quot;&quot;&quot;add &#39;skip&#39; to the template&#39;s n=
amespace. =A0This method is called _after_ update()&quot;&quot;&quot;</div>
<div>=A0=A0 =A0 =A0 =A0namespace =3D super(MyViewletClass, self).default_na=
mespace()</div><div>=A0=A0 =A0 =A0 =A0namespace[&#39;skip&#39;] =3D self.sk=
ip</div><div>=A0=A0 =A0 =A0 =A0return namespace</div></div><div><br></div><=
div>Cheers,</div><div>Andy</div>
<br><div class=3D"gmail_quote">On Wed, Jun 8, 2011 at 6:37 AM, Jonathan Bow=
las <span dir=3D"ltr">&lt;<a href=3D"mailto:j.bowlas-hclig2XLE9Zaa/[email protected]">j.bowlas@uc=
l.ac.uk</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Is there an example infrae extension or theme where the filter method<br>
is overridden?<br>
<font color=3D"#888888"><br>
J<br>
</font><div><div></div><div class=3D"h5"><br>
On 8 June 2011 12:35, Jonathan Bowlas &lt;<a href=3D"mailto:[email protected]=
.uk">j.bowlas-hclig2XLE9Zaa/[email protected]</a>&gt; wrote:<br>
&gt; Sorry but it&#39;s still not working, I did this:<br>
&gt;<br>
&gt; class LeftColumn(silvaviews.ViewletManager):<br>
&gt; =A0 =A0&quot;&quot;&quot;Left Content Area<br>
&gt; =A0 =A0&quot;&quot;&quot;<br>
&gt; =A0 =A0def filter(self):<br>
&gt; =A0 =A0 =A0 =A0 viewlets =3D super(LeftColumn, self).filter()<br>
&gt; =A0 =A0 =A0 =A0 return [v for v in viewlets if v.available()]<br>
&gt;<br>
&gt; But it returns this traceback:<br>
&gt;<br>
&gt; 2011-06-08 12:30:35,868 ERROR [infrae.wsgi]<br>
&gt; Error while rendering error message<br>
&gt; Object class: Products.Silva.Root.Root<br>
&gt; Object path: /silva<br>
&gt; Request URL: <a href=3D"http://localhost:8080/silva/test/@@index.html"=
 target=3D"_blank">http://localhost:8080/silva/test/@@index.html</a><br>
&gt; Request method: GET<br>
&gt; User: admin<br>
&gt; User-agent: Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Fire=
fox/4.0.1<br>
&gt; Refer: <a href=3D"http://localhost:8080/silva/test" target=3D"_blank">=
http://localhost:8080/silva/test</a><br>
&gt; Traceback (innermost last):<br>
&gt; =A0Module infrae.wsgi.publisher, line 183, in error<br>
&gt; =A0Module silva.core.views.views, line 73, in __call__<br>
&gt; =A0Module infrae.layout.components, line 105, in __call__<br>
&gt; =A0 - Published class: silva.core.layout.porto.errors.OtherErrorPage<b=
r>
&gt; =A0 - Object path: /silva<br>
&gt; =A0 - Object type: Silva Root<br>
&gt; =A0Module infrae.layout.components, line 77, in __call__<br>
&gt; =A0Module infrae.layout.components, line 70, in render<br>
&gt; =A0Module infrae.layout.components, line 67, in _render_template<br>
&gt; =A0Module five.grok.components, line 133, in render<br>
&gt; =A0Module zope.pagetemplate.pagetemplate, line 113, in pt_render<br>
&gt; =A0Module zope.tal.talinterpreter, line 271, in __call__<br>
&gt; =A0Module zope.tal.talinterpreter, line 343, in interpret<br>
&gt; =A0Module zope.tal.talinterpreter, line 531, in do_optTag_tal<br>
&gt; =A0Module zope.tal.talinterpreter, line 513, in no_tag<br>
&gt; =A0Module zope.tal.talinterpreter, line 343, in interpret<br>
&gt; =A0Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal=
<br>
&gt; =A0Module Products.PageTemplates.Expressions, line 220, in evaluateStr=
ucture<br>
&gt; =A0Module zope.tales.tales, line 696, in evaluate<br>
&gt; =A0 - URL: c:\silva-2.3.1\eggs\silva.core.layout-2.3.2-py2.6.egg\silva=
\core\layout\porto\porto_templates\<a href=3D"http://mainlayout.pt" target=
=3D"_blank">mainlayout.pt</a><br>
&gt; =A0 - Line 29, Column 4<br>
&gt; =A0 - Expression: &lt;StringExpr u&#39;layout&#39;&gt;<br>
&gt; =A0 - Names:<br>
&gt; =A0 =A0 =A0{&#39;args&#39;: (),<br>
&gt; =A0 =A0 =A0 &#39;container&#39;: &lt;Root at /silva&gt;,<br>
&gt; =A0 =A0 =A0 &#39;context&#39;: &lt;Root at /silva&gt;,<br>
&gt; =A0 =A0 =A0 &#39;default&#39;: &lt;object object at 0x01AD1720&gt;,<br=
>
&gt; =A0 =A0 =A0 &#39;here&#39;: &lt;Root at /silva&gt;,<br>
&gt; =A0 =A0 =A0 &#39;layout&#39;:<br>
&gt; &lt;silvatheme.uclcorporateidentity.uclcorporateidentity.MainErrorLayo=
ut<br>
&gt; object at 0x0722CE10&gt;,<br>
&gt; =A0 =A0 =A0 &#39;loop&#39;: {},<br>
&gt; =A0 =A0 =A0 &#39;nothing&#39;: None,<br>
&gt; =A0 =A0 =A0 &#39;options&#39;: {},<br>
&gt; =A0 =A0 =A0 &#39;repeat&#39;: &lt;Products.PageTemplates.Expressions.S=
afeMapping<br>
&gt; object at 0x0721D660&gt;,<br>
&gt; =A0 =A0 =A0 &#39;request&#39;: &lt;WSGIRequest,<br>
&gt; URL=3D<a href=3D"http://localhost:8080/silva/test/@@index.html" target=
=3D"_blank">http://localhost:8080/silva/test/@@index.html</a>&gt;,<br>
&gt; =A0 =A0 =A0 &#39;root&#39;: &lt;Application at &gt;,<br>
&gt; =A0 =A0 =A0 &#39;static&#39;: &lt;silva.resourceinclude.resource.Resou=
rceView object<br>
&gt; at 0x0722C750&gt;,<br>
&gt; =A0 =A0 =A0 &#39;template&#39;:<br>
&gt; &lt;Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object=
 at<br>
&gt; 0x06364A90&gt;,<br>
&gt; =A0 =A0 =A0 &#39;traverse_subpath&#39;: [],<br>
&gt; =A0 =A0 =A0 &#39;user&#39;: &lt;User &#39;admin&#39;&gt;,<br>
&gt; =A0 =A0 =A0 &#39;view&#39;: &lt;silva.core.layout.porto.errors.OtherEr=
rorPage object<br>
&gt; at 0x06A63BF0&gt;,<br>
&gt; =A0 =A0 =A0 &#39;views&#39;: &lt;Products.Five.browser.pagetemplatefil=
e.ViewMapper<br>
&gt; object at 0x0723A6D0&gt;}<br>
&gt; =A0Module zope.contentprovider.tales, line 80, in __call__<br>
&gt; =A0Module grokcore.viewlet.components, line 80, in render<br>
&gt; =A0Module five.grok.components, line 133, in render<br>
&gt; =A0Module zope.pagetemplate.pagetemplate, line 113, in pt_render<br>
&gt; =A0Module zope.tal.talinterpreter, line 271, in __call__<br>
&gt; =A0Module zope.tal.talinterpreter, line 343, in interpret<br>
&gt; =A0Module zope.tal.talinterpreter, line 533, in do_optTag_tal<br>
&gt; =A0Module zope.tal.talinterpreter, line 518, in do_optTag<br>
&gt; =A0Module zope.tal.talinterpreter, line 513, in no_tag<br>
&gt; =A0Module zope.tal.talinterpreter, line 343, in interpret<br>
&gt; =A0Module zope.tal.talinterpreter, line 852, in do_condition<br>
&gt; =A0Module zope.tal.talinterpreter, line 343, in interpret<br>
&gt; =A0Module zope.tal.talinterpreter, line 531, in do_optTag_tal<br>
&gt; =A0Module zope.tal.talinterpreter, line 513, in no_tag<br>
&gt; =A0Module zope.tal.talinterpreter, line 343, in interpret<br>
&gt; =A0Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal=
<br>
&gt; =A0Module Products.PageTemplates.Expressions, line 220, in evaluateStr=
ucture<br>
&gt; =A0Module zope.tales.tales, line 696, in evaluate<br>
&gt; =A0 - URL: c:\silva-2.3.1\src\silvatheme.uclcorporateidentity\silvathe=
me\uclcorporateidentity\uclcorporateidentity_templates\<a href=3D"http://la=
yout.pt" target=3D"_blank">layout.pt</a><br>
&gt; =A0 - Line 5, Column 8<br>
&gt; =A0 - Expression: &lt;StringExpr u&#39;threecolumn&#39;&gt;<br>
&gt; =A0 - Names:<br>
&gt; =A0 =A0 =A0{&#39;args&#39;: (),<br>
&gt; =A0 =A0 =A0 &#39;container&#39;: &lt;Root at /silva&gt;,<br>
&gt; =A0 =A0 =A0 &#39;context&#39;: &lt;Root at /silva&gt;,<br>
&gt; =A0 =A0 =A0 &#39;default&#39;: &lt;object object at 0x01AD1720&gt;,<br=
>
&gt; =A0 =A0 =A0 &#39;here&#39;: &lt;Root at /silva&gt;,<br>
&gt; =A0 =A0 =A0 &#39;layout&#39;:<br>
&gt; &lt;silvatheme.uclcorporateidentity.uclcorporateidentity.MainErrorLayo=
ut<br>
&gt; object at 0x0722CE10&gt;,<br>
&gt; =A0 =A0 =A0 &#39;loop&#39;: {},<br>
&gt; =A0 =A0 =A0 &#39;nothing&#39;: None,<br>
&gt; =A0 =A0 =A0 &#39;options&#39;: {},<br>
&gt; =A0 =A0 =A0 &#39;provider&#39;:<br>
&gt; &lt;silvatheme.uclcorporateidentity.uclcorporateidentity.Layout object=
 at<br>
&gt; 0x072033F0&gt;,<br>
&gt; =A0 =A0 =A0 &#39;repeat&#39;: &lt;Products.PageTemplates.Expressions.S=
afeMapping<br>
&gt; object at 0x0721D690&gt;,<br>
&gt; =A0 =A0 =A0 &#39;request&#39;: &lt;WSGIRequest,<br>
&gt; URL=3D<a href=3D"http://localhost:8080/silva/test/@@index.html" target=
=3D"_blank">http://localhost:8080/silva/test/@@index.html</a>&gt;,<br>
&gt; =A0 =A0 =A0 &#39;root&#39;: &lt;Application at &gt;,<br>
&gt; =A0 =A0 =A0 &#39;static&#39;: &lt;silva.resourceinclude.resource.Resou=
rceView object<br>
&gt; at 0x07234D30&gt;,<br>
&gt; =A0 =A0 =A0 &#39;template&#39;:<br>
&gt; &lt;Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object=
 at<br>
&gt; 0x063EF510&gt;,<br>
&gt; =A0 =A0 =A0 &#39;traverse_subpath&#39;: [],<br>
&gt; =A0 =A0 =A0 &#39;user&#39;: &lt;User &#39;admin&#39;&gt;,<br>
&gt; =A0 =A0 =A0 &#39;view&#39;: &lt;silva.core.layout.porto.errors.OtherEr=
rorPage object<br>
&gt; at 0x06A63BF0&gt;,<br>
&gt; =A0 =A0 =A0 &#39;viewletmanager&#39;:<br>
&gt; &lt;silvatheme.uclcorporateidentity.uclcorporateidentity.Layout object=
 at<br>
&gt; 0x072033F0&gt;,<br>
&gt; =A0 =A0 =A0 &#39;views&#39;: &lt;Products.Five.browser.pagetemplatefil=
e.ViewMapper<br>
&gt; object at 0x07234DB0&gt;}<br>
&gt; =A0Module zope.contentprovider.tales, line 80, in __call__<br>
&gt; =A0Module grokcore.viewlet.components, line 80, in render<br>
&gt; =A0Module five.grok.components, line 133, in render<br>
&gt; =A0Module zope.pagetemplate.pagetemplate, line 113, in pt_render<br>
&gt; =A0Module zope.tal.talinterpreter, line 271, in __call__<br>
&gt; =A0Module zope.tal.talinterpreter, line 343, in interpret<br>
&gt; =A0Module zope.tal.talinterpreter, line 531, in do_optTag_tal<br>
&gt; =A0Module zope.tal.talinterpreter, line 513, in no_tag<br>
&gt; =A0Module zope.tal.talinterpreter, line 343, in interpret<br>
&gt; =A0Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal=
<br>
&gt; =A0Module Products.PageTemplates.Expressions, line 220, in evaluateStr=
ucture<br>
&gt; =A0Module zope.tales.tales, line 696, in evaluate<br>
&gt; =A0 - URL: c:\silva-2.3.1\src\silvatheme.uclcorporateidentity\silvathe=
me\uclcorporateidentity\uclcorporateidentity_templates\<a href=3D"http://th=
reecolumn.pt" target=3D"_blank">threecolumn.pt</a><br>
&gt; =A0 - Line 6, Column 12<br>
&gt; =A0 - Expression: &lt;StringExpr u&#39;leftcolumn&#39;&gt;<br>
&gt; =A0 - Names:<br>
&gt; =A0 =A0 =A0{&#39;args&#39;: (),<br>
&gt; =A0 =A0 =A0 &#39;container&#39;: &lt;Root at /silva&gt;,<br>
&gt; =A0 =A0 =A0 &#39;context&#39;: &lt;Root at /silva&gt;,<br>
&gt; =A0 =A0 =A0 &#39;default&#39;: &lt;object object at 0x01AD1720&gt;,<br=
>
&gt; =A0 =A0 =A0 &#39;here&#39;: &lt;Root at /silva&gt;,<br>
&gt; =A0 =A0 =A0 &#39;layout&#39;:<br>
&gt; &lt;silvatheme.uclcorporateidentity.uclcorporateidentity.MainErrorLayo=
ut<br>
&gt; object at 0x0722CE10&gt;,<br>
&gt; =A0 =A0 =A0 &#39;loop&#39;: {},<br>
&gt; =A0 =A0 =A0 &#39;nothing&#39;: None,<br>
&gt; =A0 =A0 =A0 &#39;options&#39;: {},<br>
&gt; =A0 =A0 =A0 &#39;provider&#39;:<br>
&gt; &lt;silvatheme.uclcorporateidentity.uclcorporateidentity.ThreeColumn<b=
r>
&gt; object at 0x07234ED0&gt;,<br>
&gt; =A0 =A0 =A0 &#39;repeat&#39;: &lt;Products.PageTemplates.Expressions.S=
afeMapping<br>
&gt; object at 0x0721D6F0&gt;,<br>
&gt; =A0 =A0 =A0 &#39;request&#39;: &lt;WSGIRequest,<br>
&gt; URL=3D<a href=3D"http://localhost:8080/silva/test/@@index.html" target=
=3D"_blank">http://localhost:8080/silva/test/@@index.html</a>&gt;,<br>
&gt; =A0 =A0 =A0 &#39;root&#39;: &lt;Application at &gt;,<br>
&gt; =A0 =A0 =A0 &#39;static&#39;: &lt;silva.resourceinclude.resource.Resou=
rceView object<br>
&gt; at 0x07234F30&gt;,<br>
&gt; =A0 =A0 =A0 &#39;template&#39;:<br>
&gt; &lt;Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object=
 at<br>
&gt; 0x063EF7D0&gt;,<br>
&gt; =A0 =A0 =A0 &#39;traverse_subpath&#39;: [],<br>
&gt; =A0 =A0 =A0 &#39;user&#39;: &lt;User &#39;admin&#39;&gt;,<br>
&gt; =A0 =A0 =A0 &#39;view&#39;: &lt;silva.core.layout.porto.errors.OtherEr=
rorPage object<br>
&gt; at 0x06A63BF0&gt;,<br>
&gt; =A0 =A0 =A0 &#39;viewletmanager&#39;:<br>
&gt; &lt;silvatheme.uclcorporateidentity.uclcorporateidentity.ThreeColumn<b=
r>
&gt; object at 0x07234ED0&gt;,<br>
&gt; =A0 =A0 =A0 &#39;views&#39;: &lt;Products.Five.browser.pagetemplatefil=
e.ViewMapper<br>
&gt; object at 0x07234F50&gt;}<br>
&gt; =A0Module zope.contentprovider.tales, line 77, in __call__<br>
&gt; =A0Module zope.viewlet.manager, line 104, in update<br>
&gt; TypeError: filter() takes exactly 1 argument (2 given)<br>
&gt;<br>
&gt; Any Ideas?<br>
&gt;<br>
&gt;<br>
&gt; On 8 June 2011 11:43, Antonin AMAND &lt;<a href=3D"mailto:antonin@infr=
ae.com">[email protected]</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt; The viewlet still rendered even though theres no index_lef=
t.<br>
&gt;&gt;&gt;&gt; Then I checked the documentation here<br>
&gt;&gt;&gt;&gt; <a href=3D"http://pypi.python.org/pypi/zope.viewlet" targe=
t=3D"_blank">http://pypi.python.org/pypi/zope.viewlet</a>, specifically the=
<br>
&gt;&gt;&gt;&gt; &#39;ConditionalViewletManager&#39; section where it state=
s that Viewlets have<br>
&gt;&gt;&gt;&gt; an &#39;available&#39; attribute (not a method), so I trie=
d setting available<br>
&gt;&gt;&gt;&gt; =3D False, =A0but still the viewlet rendered.<br>
&gt;&gt;<br>
&gt;&gt; You&#39;re right, Viewlet have no available method, I&#39;ve been =
mistaken.<br>
&gt;&gt; What we usually do is this:<br>
&gt;&gt;<br>
&gt;&gt; In the viewlet manager we override the filters method :<br>
&gt;&gt;<br>
&gt;&gt; class MyViewletManager(...):<br>
&gt;&gt; =A0 ...<br>
&gt;&gt; =A0 def filter(self):<br>
&gt;&gt; =A0 =A0 =A0viewlets =3D super(MyViewletManager, self).filter()<br>
&gt;&gt; =A0 =A0 =A0return [v for v in viewlets if v.available()]<br>
&gt;&gt;<br>
&gt;&gt; Then define an available method on all viewlets of this ViewletMan=
ager.<br>
&gt;&gt;<br>
&gt;&gt; BTW, be carefull with hasattr(self.context, &#39;index_left&#39;),=
 it checks<br>
&gt;&gt; with acquisition.<br>
&gt;&gt;<br>
&gt;&gt; Antonin<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; silva-dev mailing list<br>
&gt;&gt; <a href=3D"mailto:silva-dev-IAPFreCvJWM6s/[email protected]">[email protected]=
ae.com</a><br>
&gt;&gt; <a href=3D"https://lists.infrae.com/mailman/listinfo/silva-dev" ta=
rget=3D"_blank">https://lists.infrae.com/mailman/listinfo/silva-dev</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Jonathan Bowlas<br>
&gt; Web Support Officer<br>
&gt; Media Services<br>
&gt; University College London<br>
&gt; Email: <a href=3D"mailto:j.bowlas-hclig2XLE9Zaa/[email protected]">j.bowlas-hclig2XLE9Zaa/[email protected]</a><br=
>
&gt;<br>
<br>
<br>
<br>
--<br>
Jonathan Bowlas<br>
Web Support Officer<br>
Media Services<br>
University College London<br>
Email: <a href=3D"mailto:j.bowlas-hclig2XLE9Zaa/[email protected]">j.bowlas-hclig2XLE9Zaa/[email protected]</a><br>
_______________________________________________<br>
silva-dev mailing list<br>
<a href=3D"mailto:silva-dev-IAPFreCvJWM6s/[email protected]">silva-dev-IAPFreCvJWM6s/[email protected]</a=
><br>
<a href=3D"https://lists.infrae.com/mailman/listinfo/silva-dev" target=3D"_=
blank">https://lists.infrae.com/mailman/listinfo/silva-dev</a><br>
</div></div></blockquote></div><br></div>

--000e0cd56864c0036404a5326f72--

--===============4390400384123977920==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
silva-dev mailing list
silva-dev-IAPFreCvJWM6s/[email protected]
https://lists.infrae.com/mailman/listinfo/silva-dev

--===============4390400384123977920==--