[Grok-dev] a grok.getApplication() implementation
ct at gocept.com
Fri Nov 27 01:18:03 EST 2009
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.
> I'd really like this function available in Grok, so I put together an
> implementation, and some tests for it, available on a branch:
> 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
> # 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.
Christian Theune · ct at gocept.com
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 0 · fax +49 345 1229889 1
Zope and Plone consulting and development
More information about the Grok-dev