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

Martijn Faassen faassen at startifact.com
Thu May 8 10:53:34 EDT 2008


Hi there,

Jan-Wijbrand Kolman wrote:
> See https://bugs.launchpad.net/grok/+bug/226555

> The current url() methods on viewlets and viewletmanagers are broken. 
> They apparently returns incorrect URLs, the code is duplicated all over 
> the place, and on the trunk these methods have not been updated 
> according the updates the view.url() got during the Grokkerdam sprint 
> and there're no tests.

A correct summary of what's wrong. :)

> I assigned myself to the issue and I've been working on a fix for a bit, 
> but I need your help.
> 
> Let me try to summarize my thinking:
> 
> The url() methods for viewletmanagers and viewlets should return 
> basically *identical* URLs to what the url() method on a regular view 
> for the same object would return.
> 
> * Question: is this interpretation of the issue correct?

That is my interpretation. I'd like someone more experienced about 
viewlets to chip in on this, though.

> * 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.


> In order to re-implement the url() methods on viewlet(manager), the 
> viewlet(manager) instance needs a reference to the view it was adapted 
> to (together with the context object and request). Looking at the 
> viewlet(manager) interfaces in zope.viewlet and zope.contentprovider, 
> this relationship is expressed through the __parent__ attribute on the 
> viewlet(manager).
> 
> * Question: allthough I see the necessity for calling this attribute 
> '__parent__', I can imagine having it assigned to an attribute called 
> 'view' as well would make it slightly more obvious how to use it for the 
> developer using viewlets. Would that be an idea?

The confusion here is that 'view' in the context of a viewlet template 
is actually the viewlet. I think...

I'd say go with the __parent__ thing for the time being. I don't know 
what the Zope 3 story is.

[snip]
> * Question: is it then actually a good thing that Grok extends the 
> viewlet (and contentprovider) interfaces? Or in other words, isn't the 
> bug really that there *is* a url method and should it thus be removed?

I think it's fine to extend these. viewletmanagers are frequently 
extended; it's their design. Since we extend views as well (for 
convenience reasons), I think we should extend viewlets as well, also 
for convenience. It think it would be good if viewlets acted like views 
a lot in the API they provide. Makes them easier to explain, and 
hopefully allows a lot of code sharing.

Regards,

Martijn



More information about the Grok-dev mailing list