[Grok-dev] a grok.getApplication() implementation

Martijn Faassen faassen at startifact.com
Fri Nov 27 05:38:30 EST 2009


Christian Theune wrote:
> On 11/27/2009 02:22 AM, Kevin Teague wrote:
>> The grok.getApplication() has been discussed/proposed a few times in
>> the past, e.g.
>>
>> http://article.gmane.org/gmane.comp.web.zope.grok.devel/5521
>>
>> I'd really like this function available in Grok, so I put together an
>> implementation, and some tests for it, available on a branch:
>>
>> http://svn.zope.org/grok/branches/kteague-getapp/
>>
>> The implementation, in grok.utils, just looks like this:
>>
>> def getApplication():
>>      """Get the application."""
>>      site = grok.getSite()
>>      if grok.interfaces.IApplication.providedBy(site):
>>          return site
>>      else:
>>          # another sub-site is within the application, walk up
>>          # the tree until we get to the application
>>          parent = site.__parent__
>>          while not grok.interfaces.IApplication.providedBy(parent):
>>              parent = parent.__parent__
>>          return parent
>>
>> Not sure if there is a better way to do this?
> 
> There already is an implementation that acquires the application from a 
> view to return its URL.
> 
> In my projects I tend to complement that implementation with the same 
> algorithm that just returns the object instead of getting the URL.

I think Kevin's looks like a reasonable implementation and it mirrors 
getSite(), so I'm +1.

I don't find myself using application_url for some reason.

Regards,

Martijn




More information about the Grok-dev mailing list