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

Kevin Teague kevin at bud.ca
Thu Nov 26 20:22:02 EST 2009


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?

The tests are in src/grok/ftests/application/, they could maybe be
improved as my Site() zen is also not super great. Although this
feature is relatively simple, so perhaps it's good enough to be merged
to trunk?

(docs need to be updated to, I can do this post-merge)


More information about the Grok-dev mailing list