[Grok-dev] Trying to understand viewlets
Souheil CHELFOUH
trollfot at gmail.com
Fri Dec 16 22:32:47 UTC 2011
For this kind of things, we usually use marker interfaces
Marker interfaces are simple interfaces with nothing defined in them,
used a bit like "tags"
class ICoolView(Interface):
"""Views tagged with this are cool
"""
then, in you views :
class SomeCoolView(grok.View):
...
grok.implements(ICoolView)
....
class MySmashingView(grok.View):
...
grok.implements(ICoolView)
....
finally, in your viewlets :
class MyViewlet(grok.Viewlet):
grok.view(ICoolView)
and you've got your thing working
2011/12/16 Àlex Magaz Graça <rivaldi8 at gmail.com>:
> Hi,
>
> I've just converted my application to use viewlets instead of only views.
> After the conversion, some doubts have arisen about which is the correct way
> to use them.
>
> Right now, I have all the code in the update() method from the views. The
> viewlets don't have any method, only grok directives binding them to views,
> viewlet managers and templates.
>
> But, as I see it, it should be the other way round. The code in
> Viewlet.update() and only directives in the views. This would allow to reuse
> a viewlet in different views. However, I can't bind a viewlet to more than a
> View. I've tryied the following, but both fail:
>
> class TestViewlet(grok.Viewlet):
> grok.View(SomeView)
> grok.View(SomeOtherView)
>
> grok.View(SomeView, SomeOtherView)
>
> The use case I'm thinking is for example a viewlet that displays a list of
> objects. I would want to bind it to a view which only shows this list, but I
> would also want to link it to a kind of dashboard view where it is rendered
> along with other viewlets showing other information.
>
> I this the correct/usual way of using viewlets?
>
> Thanks,
> Àlex
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
>
More information about the Grok-dev
mailing list