[Grok-dev] Re: Getting the application in views and viewlets

Martijn Faassen faassen at startifact.com
Thu Jun 19 11:56:48 EDT 2008


Graham Stratton wrote:
[snip]
> My suggestion wasn't as much about viewlets as about making the 
> application object available in templates. It's currently quite tricky 
> to get the application anywhere, and I'm still not sure what's 
> considered the correct way to do it, whether by utility lookup or 
> traversing __parent__ until we find the Application.

I think we might want to implement grok.getApplication().

What the right implementation should be I'm not sure about. You could do 
it by traversing __parent__ until you find the Application.

You could also do it by looking up getSite, checking whether it's the 
application, and then if not walk up the __parent__ chain from the site. 
This would be slightly faster in many common cases.

Alternatively you could register the application as a local utility in 
the application itself upon creation. This would allow the local utility 
lookup machinery to do everything for you. The drawback is that it'd 
need a content upgrade for existing applications to become equipped with 
this existing application.

Graham, patches are welcome. I think the getSite() approach might be the 
best approach right now.

Regards,

Martijn



More information about the Grok-dev mailing list