[Grok-dev] Re: issue #226555: viewlet.url() and how to solve it

Kevin Smith kevin at mcweekly.com
Thu May 8 14:48:06 EDT 2008



Martijn Faassen wrote:
> Hey Kevin,
>
> Thanks for your feedback!
>
> Kevin Smith wrote:
> [snip]
>> Thinking out loud, it may be possible in a viewlet to map the 'view'
>>  namespace directly to the parent view and then supply a 'viewlet' 
>> namespace that maps directly to the viewlet.
>
> This sounds attractive. It of course makes sense to have 'view'
> still map to a view, and a viewlet will always
> have a view available. It will work for the refactoring a view into 
> viewlets use case, and it makes it clear whether you're accessing 
> methods on a view or a viewlet.
>
> +1 for exploring this: a 'view' namespace in the template which points 
> to a real view, and a 'viewlet' namespace in the template that points 
> to the viewlet. I think in this case it would make sense to establish 
> a 'view' attribute in the viewlet class as well.
>
> One thing we need to check is how Zope 3's viewlets support does it 
> now. What does 'view' mean in a viewlet's template in straight Zope 3? 
> We shouldn't necessarily follow this approach, but we should at least 
> be aware of what it's doing.

class ViewletBase(BrowserView):
    """Viewlet adapter class used in meta directive as a mixin class."""

    zope.interface.implements(interfaces.IViewlet)

    def __init__(self, context, request, view, manager):
        super(ViewletBase, self).__init__(context, request)
        self.__parent__ = view
        self.context = context
        self.request = request
        self.manager = manager

Looks like __parent__ is the view, and manager is the viewletmanager.... 
I'm not sure the viewlet is actually accessible here at all.

>
>>>> * Related question: during the sprint someone expressed the
>>>> desire for a way to construct URLs to individual viewlets. How
>>>> does that relate to this issue? Or should we ignore this for now?
>>>>
>>>
>>> Ignore this for now; viewlets don't really have URLs (yet) in Grok
>>>  anyway.
>> +1, this is muddying up the issue and it is really a separate case. I
>>  propose implementing a new type of viewlet to signify such extended
>>  functionality, like ViewletPage or something.
>
> Alternatively a directive to do such exposure. Though for the general
> caching scenario where you want to use a caching server like Varnish and
> do re-integration later, you'd need URLs for all viewlets. Anyway,
> another topic.
>
> Regards,
>
> Martijn
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>
>



More information about the Grok-dev mailing list