[Checkins] SVN: grok/branches/kteague-getapp/src/grok/ first draft of grok.getApplication() - need to figure out how to test this still.
Kevin Teague
kevin at bud.ca
Tue Feb 17 21:17:15 EST 2009
Log message for revision 96659:
first draft of grok.getApplication() - need to figure out how to test this still.
Changed:
U grok/branches/kteague-getapp/src/grok/__init__.py
U grok/branches/kteague-getapp/src/grok/interfaces.py
U grok/branches/kteague-getapp/src/grok/util.py
-=-
Modified: grok/branches/kteague-getapp/src/grok/__init__.py
===================================================================
--- grok/branches/kteague-getapp/src/grok/__init__.py 2009-02-18 01:42:27 UTC (rev 96658)
+++ grok/branches/kteague-getapp/src/grok/__init__.py 2009-02-18 02:17:14 UTC (rev 96659)
@@ -79,6 +79,8 @@
from grok.directive import (
local_utility, permissions, site, restskin, traversable)
+from grok.util import getApplication
+
# BBB These two functions are meant for test fixtures and should be
# imported from grok.testing, not from grok.
from grok.testing import grok, grok_component
Modified: grok/branches/kteague-getapp/src/grok/interfaces.py
===================================================================
--- grok/branches/kteague-getapp/src/grok/interfaces.py 2009-02-18 01:42:27 UTC (rev 96658)
+++ grok/branches/kteague-getapp/src/grok/interfaces.py 2009-02-18 02:17:14 UTC (rev 96659)
@@ -153,6 +153,8 @@
def getSite():
"""Get the current site."""
+ def getApplication():
+ """Get the application."""
IRESTSkinType = interface.Attribute('The REST skin type')
Modified: grok/branches/kteague-getapp/src/grok/util.py
===================================================================
--- grok/branches/kteague-getapp/src/grok/util.py 2009-02-18 01:42:27 UTC (rev 96658)
+++ grok/branches/kteague-getapp/src/grok/util.py 2009-02-18 02:17:14 UTC (rev 96659)
@@ -18,6 +18,8 @@
from zope.security.checker import NamesChecker, defineChecker
from grokcore.security.util import check_permission
+from zope.app.component.hooks import getSite
+from grok.interfaces import IApplication
def make_checker(factory, view_factory, permission, method_names=None):
"""Make a checker for a view_factory associated with factory.
@@ -56,3 +58,16 @@
# Add the new skin.
ifaces.append(skin)
interface.directlyProvides(request, *ifaces)
+
+def getApplication():
+ """Get the application."""
+ site = getSite()
+ if 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 IApplication.providedBy(parent):
+ parent = parent.__parent__
+ return parent
More information about the Checkins
mailing list