[CMF-checkins] SVN: CMF/branches/jens_tools_as_utilities/CMF - Make
the site into a utility providing ISiteRoot
Jens Vagelpohl
jens at dataflake.org
Sun Mar 4 08:33:59 EST 2007
Log message for revision 72969:
- Make the site into a utility providing ISiteRoot
Changed:
U CMF/branches/jens_tools_as_utilities/CMFCore/URLTool.py
U CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionsTool.py
U CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_URLTool.py
U CMF/branches/jens_tools_as_utilities/CMFDefault/PropertiesTool.py
U CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml
-=-
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/URLTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/URLTool.py 2007-03-04 13:31:08 UTC (rev 72968)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/URLTool.py 2007-03-04 13:33:59 UTC (rev 72969)
@@ -21,6 +21,8 @@
from Globals import DTMLFile
from Globals import InitializeClass
from OFS.SimpleItem import SimpleItem
+
+from zope.component import getUtility
from zope.interface import implements
from ActionProviderBase import ActionProviderBase
@@ -75,15 +77,7 @@
def getPortalObject(self):
""" Get the portal object itself.
"""
- portal = aq_inner(self)
- while True:
- portal = getattr(portal, 'aq_parent', None)
- if portal is None:
- break
- if ISiteRoot.providedBy(portal):
- return portal
- # Portal could not be found, log an error or raise one?
- return aq_inner(self)
+ return getUtility(ISiteRoot)
security.declarePublic('getRelativeContentPath')
def getRelativeContentPath(self, content):
@@ -110,4 +104,3 @@
InitializeClass(URLTool)
registerToolInterface('portal_url', IURLTool)
-
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionsTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionsTool.py 2007-03-04 13:31:08 UTC (rev 72968)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_ActionsTool.py 2007-03-04 13:33:59 UTC (rev 72969)
@@ -30,6 +30,7 @@
from Products.CMFCore.tests.base.testcase import SecurityRequestTest
from Products.CMFCore.URLTool import URLTool
from Products.CMFCore.interfaces import IMembershipTool
+from Products.CMFCore.interfaces import ISiteRoot
class ActionsToolTests(unittest.TestCase):
@@ -113,6 +114,7 @@
root = self.root
sm = getSiteManager()
+ sm.registerUtility(root, ISiteRoot)
root._setObject( 'portal_actions', self._makeOne() )
root._setObject( 'portal_url', URLTool() )
sm.registerUtility(root.portal_url, IURLTool)
Modified: CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_URLTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_URLTool.py 2007-03-04 13:31:08 UTC (rev 72968)
+++ CMF/branches/jens_tools_as_utilities/CMFCore/tests/test_URLTool.py 2007-03-04 13:33:59 UTC (rev 72969)
@@ -18,6 +18,9 @@
import unittest
import Testing
+from zope.component import getSiteManager
+
+from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.tests.base.dummy import DummyContent
from Products.CMFCore.tests.base.dummy import DummyFolder
from Products.CMFCore.tests.base.dummy import DummySite
@@ -27,6 +30,8 @@
def setUp(self):
self.site = DummySite(id='foo')
+ sm = getSiteManager()
+ sm.registerUtility(self.site, ISiteRoot)
def _makeOne(self, *args, **kw):
from Products.CMFCore.URLTool import URLTool
Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/PropertiesTool.py
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/PropertiesTool.py 2007-03-04 13:31:08 UTC (rev 72968)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/PropertiesTool.py 2007-03-04 13:33:59 UTC (rev 72969)
@@ -26,6 +26,7 @@
from Products.CMFCore.ActionProviderBase import ActionProviderBase
from Products.CMFCore.interfaces import IPropertiesTool
+from Products.CMFCore.interfaces import ISiteRoot
from Products.CMFCore.interfaces.portal_properties \
import portal_properties as z2IPropertiesTool
from Products.CMFCore.utils import registerToolInterface
@@ -63,8 +64,7 @@
security.declareProtected(ManagePortal, 'editProperties')
def editProperties(self, props):
'''Change portal settings'''
- # XXX: We need a better way to get the site!
- site = getSite() or aq_parent(aq_inner(self))
+ site = getUtility(ISiteRoot)
site.manage_changeProperties(props)
getUtility(IMailHost).smtp_host = props['smtp_server']
if hasattr(self, 'propertysheets'):
@@ -73,9 +73,7 @@
ps.props.manage_changeProperties(props)
def title(self):
- # XXX: We need a better way to get the site!
- site = getSite() or aq_parent(aq_inner(self))
- return site.title
+ return getUtility(ISiteRoot).title
def smtp_server(self):
return getUtility(IMailHost).smtp_host
Modified: CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml
===================================================================
--- CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml 2007-03-04 13:31:08 UTC (rev 72968)
+++ CMF/branches/jens_tools_as_utilities/CMFDefault/profiles/default/componentregistry.xml 2007-03-04 13:33:59 UTC (rev 72969)
@@ -36,6 +36,9 @@
interface="Products.CMFCore.interfaces.IRegistrationTool"
object="/portal_registration"/>
<utility
+ interface="Products.CMFCore.interfaces.ISiteRoot"
+ object="/"/>
+ <utility
interface="Products.CMFCore.interfaces.ISkinsTool"
object="/portal_skins"/>
<utility
More information about the CMF-checkins
mailing list