[Zope-Checkins]
SVN: Products.Five/branches/philikon-local-components/
New approach to local components in Zope 2,
based on Jim's new component registration
Philipp von Weitershausen
philikon at philikon.de
Tue Feb 28 19:34:35 EST 2006
Log message for revision 65631:
New approach to local components in Zope 2, based on Jim's new component registration
in the jim-adapter branch of Zope 3.
Five.component.browser actually features a CustomizationView which lets you walk up
to an object, view a list of template-based browser views of that object and lets
you customize it locally.
The simple doctest passes but some of the details still need to be worked out. In
particular, the forms really haven't been tested yet nor viewed in their rendered
form (they most probably are very ugly right now).
Changed:
A Products.Five/branches/philikon-local-components/component/
A Products.Five/branches/philikon-local-components/component/__init__.py
A Products.Five/branches/philikon-local-components/component/browser.py
A Products.Five/branches/philikon-local-components/component/component.txt
A Products.Five/branches/philikon-local-components/component/components.pt
A Products.Five/branches/philikon-local-components/component/configure.zcml
A Products.Five/branches/philikon-local-components/component/customizeview.pt
A Products.Five/branches/philikon-local-components/component/interfaces.py
A Products.Five/branches/philikon-local-components/component/templateviews.pt
A Products.Five/branches/philikon-local-components/component/tests.py
U Products.Five/branches/philikon-local-components/site/browser.py
U Products.Five/branches/philikon-local-components/site/localsite.py
U Products.Five/branches/philikon-local-components/site/tests/sitemanager.txt
U Products.Five/branches/philikon-local-components/site/tests/test_utility.py
-=-
Added: Products.Five/branches/philikon-local-components/component/__init__.py
===================================================================
--- Products.Five/branches/philikon-local-components/component/__init__.py 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/component/__init__.py 2006-03-01 00:34:35 UTC (rev 65631)
@@ -0,0 +1,67 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Component browser views
+
+$Id$
+"""
+from zope.event import notify
+from zope.interface import alsoProvides, noLongerProvides
+from zope.app.publication.zopepublication import BeforeTraverseEvent
+from zope.app.component.interfaces import ISite, IPossibleSite
+
+import ExtensionClass
+from Acquisition import aq_base
+from Products.SiteAccess.AccessRule import AccessRule
+from ZPublisher.BeforeTraverse import registerBeforeTraverse
+from ZPublisher.BeforeTraverse import unregisterBeforeTraverse
+
+# Hook up custom component architecture calls
+import zope.app.component.hooks
+zope.app.component.hooks.setHooks()
+
+class LocalSiteHook(ExtensionClass.Base):
+
+ def __call__(self, container, request):
+ notify(BeforeTraverseEvent(container, request))
+
+HOOK_NAME = '__local_site_hook__'
+
+def enableSite(obj, iface=ISite):
+ """Install __before_traverse__ hook for Local Site
+ """
+ # We want the original object, not stuff in between, and no acquisition
+ obj = aq_base(obj)
+ if not IPossibleSite.providedBy(obj):
+ raise TypeError, 'Must provide IPossibleSite'
+ hook = AccessRule(HOOK_NAME)
+ registerBeforeTraverse(obj, hook, HOOK_NAME, 1)
+
+ if not hasattr(obj, HOOK_NAME):
+ setattr(obj, HOOK_NAME, LocalSiteHook())
+
+ alsoProvides(obj, iface)
+
+def disableSite(obj, iface=ISite):
+ """Remove __before_traverse__ hook for Local Site
+ """
+ # We want the original object, not stuff in between, and no acquisition
+ obj = aq_base(obj)
+ if not iface.providedBy(obj):
+ raise TypeError('Object must be a site.')
+
+ unregisterBeforeTraverse(obj, HOOK_NAME)
+ if hasattr(obj, HOOK_NAME):
+ delattr(obj, HOOK_NAME)
+
+ noLongerProvides(obj, iface)
Property changes on: Products.Five/branches/philikon-local-components/component/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Products.Five/branches/philikon-local-components/component/browser.py
===================================================================
--- Products.Five/branches/philikon-local-components/component/browser.py 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/component/browser.py 2006-03-01 00:34:35 UTC (rev 65631)
@@ -0,0 +1,134 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Component browser views
+
+$Id$
+"""
+from Acquisition import aq_parent
+from Products.Five.browser import BrowserView
+from Products.Five.component import enableSite, disableSite
+from Products.Five.component.interfaces import IObjectManagerSite
+
+from zope.interface import providedBy
+from zope.component import getMultiAdapter
+from zope.component.globalregistry import base
+from zope.component.persistentregistry import PersistentComponents
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.app.component.hooks import clearSite
+from zope.app.zptpage import ZPTPage
+from zope.app.apidoc.presentation import getViews, getViewInfoDictionary
+
+class ComponentsView(BrowserView):
+
+ def update(self):
+ form = self.request.form
+ if form.has_key('MAKESITE'):
+ self.makeSite()
+ elif form.has_key('UNMAKESITE'):
+ self.unmakeSite()
+
+ def isSite(self):
+ return IObjectManagerSite.providedBy(self.context)
+
+ def makeSite(self):
+ if IObjectManagerSite.providedBy(self.context):
+ raise ValueError('This is already a site')
+
+ enableSite(self.context, iface=IObjectManagerSite)
+
+ components = PersistentComponents()
+ components.__bases__ = (base,)
+ self.context.setSiteManager(components)
+
+ def unmakeSite(self):
+ if not self.isSite():
+ raise ValueError('This is not a site')
+
+ disableSite(self.context)
+
+ # disableLocalSiteHook circumcised our context so that it's
+ # not an ISite anymore. That can mean that certain things for
+ # it can't be found anymore. So, for the rest of this request
+ # (which will be over in about 20 CPU cycles), already clear
+ # the local site from the thread local.
+ clearSite()
+
+ self.context.setSiteManage(None)
+
+class CustomizationView(BrowserView):
+
+ def templateViewRegistrations(self):
+ for reg in getViews(providedBy(self.context), IBrowserRequest):
+ factory = reg.factory
+ while hasattr(factory, 'factory'):
+ factory = factory.factory
+ if hasattr(factory, '__name__') and \
+ factory.__name__.startswith('SimpleViewClass'):
+ yield reg
+
+ def templateSource(self, viewname):
+ view = getMultiAdapter((self.context, self.request),
+ name=viewname)
+ return view.index.read()
+
+ def doCustomizeTemplate(self, viewname):
+ src = self.templateSource(viewname)
+
+ # find the nearest site
+ obj = self.context
+ while obj is not None and not IObjectManagerSite.providedBy(obj):
+ obj = aq_parent(obj)
+ if obj is None:
+ raise TypeError("No site found") #TODO find right exception
+
+ zpt = ZPTPage()
+ zpt.source = unicode(src)
+ obj._setOb(viewname, zpt) #XXX there could be a naming conflict
+ zpt = getattr(obj, viewname)
+ components = obj.getSiteManager()
+
+ # find out the view registration object so we can get at the
+ # provided and required interfaces
+ for reg in getViews(providedBy(self.context), IBrowserRequest):
+ if reg.name == viewname:
+ break
+
+ components.registerAdapter(ZPTViewFactory(zpt), required=reg.required,
+ provided=reg.provided, name=viewname) #XXX info?
+ return zpt
+
+ def customizeTemplate(self, viewname):
+ zpt = self.doCustomizeTemplate(viewname)
+ #TODO use @@absolute_url view
+ self.request.redirect(zpt.absolute_url() + "/manage_workspace")
+
+class ZPTViewFactory(object):
+
+ def __init__(self, zptpage):
+ self.zptpage = zptpage
+
+ def __call__(self, context, request):
+ return ZPTView(self.zptpage, context, request)
+
+class ZPTView(object):
+
+ def __init__(self, zptpage, context, request):
+ self.zptpage = zptpage
+ self.context = context
+ self.request = request
+
+ def __call__(self, **kw):
+ namespace = self.zptpage.pt_getContext(self.context, self.request, **kw)
+ namespace['view'] = self #XXX get the "real" view class
+ return self.zptpage.pt_render(namespace)
Property changes on: Products.Five/branches/philikon-local-components/component/browser.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Products.Five/branches/philikon-local-components/component/component.txt
===================================================================
--- Products.Five/branches/philikon-local-components/component/component.txt 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/component/component.txt 2006-03-01 00:34:35 UTC (rev 65631)
@@ -0,0 +1,115 @@
+(Local) components in Five
+==========================
+
+ >>> from Products.Five import zcml
+ >>> import Products.Five.component
+ >>> zcml.load_config('meta.zcml', Products.Five)
+ >>> zcml.load_config('permissions.zcml', Products.Five)
+ >>> zcml.load_config('configure.zcml', Products.Five.component)
+
+Turning ObjectManagers into a site
+----------------------------------
+
+Let's create a folder that we'll turn into a site:
+
+ >>> from OFS.ObjectManager import ObjectManager
+ >>> site = ObjectManager()
+
+Make this a real site by using a view that a) sets
+``IObjectManagerSite``, b) sets a traversal hook and c) sets a
+component registration
+
+ >>> import zope.component
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> view = zope.component.getMultiAdapter((site, request),
+ ... name=u"components.html")
+ >>> view.makeSite()
+
+Now the site provides ``IObjectManagerSite``:
+
+ >>> from Products.Five.component.interfaces import IObjectManagerSite
+ >>> IObjectManagerSite.providedBy(site)
+ True
+
+And it has a site manager (component registry):
+
+ >>> site.getSiteManager() #doctest: +ELLIPSIS
+ <zope.component.persistentregistry.PersistentComponents object at ...>
+
+
+Views on objects
+----------------
+
+Let's create a simple content object that we put into the folder
+(a.k.a. the site):
+
+ >>> from Products.Five.tests.testing.simplecontent import SimpleContent
+ >>> item = SimpleContent('item', 'An item')
+ >>> site._setOb('item', item)
+ >>> item = site.item
+
+Let's get a list of views (that also shows where each view is
+registered at):
+
+ >>> view = zope.component.getMultiAdapter((item, request),
+ ... name=u"templateviews.html")
+ >>> view = view.__of__(item)
+ >>> from pprint import pprint
+ >>> viewnames = [reg.name for reg in view.templateViewRegistrations()]
+ >>> viewnames.sort()
+ >>> pprint(viewnames)
+ [u'customizeview.html', u'templateviews.html']
+
+
+Customizing views
+-----------------
+
+We can select a view and see its template source:
+
+ >>> view = zope.component.getMultiAdapter((item, request),
+ ... name=u"customizeview.html")
+ >>> view = view.__of__(item)
+ >>> print view.templateSource(u'customizeview.html') #doctest: +ELLIPSIS
+ <html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
+ ...
+ <p i18n:translate="">This is the source of the
+ <code tal:content="request/form/viewname">viewname</code>:</p>
+ ...
+
+We now hit the customize button and get a customized ZPT template:
+
+ >>> zpt = view.doCustomizeTemplate(u'customizeview.html')
+
+That actually creates a ZPTPage object in the nearest site (perhaps
+later we'd like to have the option to pick which of the sites above us
+should be targeted)
+
+ >>> zpt = getattr(site, 'customizeview.html')
+ >>> print zpt.read() #doctest: +ELLIPSIS
+ <html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
+ ...
+ <p i18n:translate="">This is the source of the
+ <code tal:content="request/form/viewname">viewname</code>:</p>
+ ...
+
+It also registers this component as a view now, so when we look up the
+view again, we get the customized one. Therefore let us customize the
+template and look up the view. For that to work, we also need to make
+the site the current site:
+
+ >>> zpt.source = u'doctest\n'
+ >>> from zope.app.component.hooks import setSite
+ >>> setSite(site)
+ >>> view = zope.component.getMultiAdapter((item, request),
+ ... name=u"customizeview.html")
+ >>> print view()
+ doctest
+ <BLANKLINE>
+
+Clean up:
+
+ >>> from zope.app.testing.placelesssetup import tearDown
+ >>> tearDown()
Property changes on: Products.Five/branches/philikon-local-components/component/component.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Products.Five/branches/philikon-local-components/component/components.pt
===================================================================
--- Products.Five/branches/philikon-local-components/component/components.pt 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/component/components.pt 2006-03-01 00:34:35 UTC (rev 65631)
@@ -0,0 +1,29 @@
+<tal:tag condition="view/update"/>
+<html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
+ <body>
+ <div metal:fill-slot="body">
+
+ <p i18n:translate="">Sites support local configuration of components.</p>
+
+ <form action="." tal:attributes="action request/URL" method="post"
+ enctype="multipart/form-data">
+ <div class="row">
+ <div class="controls">
+ <input type="submit" value="Make site" name="MAKESITE"
+ i18n:attributes="value" tal:condition="view/isSite" />
+ <input type="submit" value="Unmake site" name="UNMAKESITE"
+ i18n:attributes="value" tal:condition="not:view/isSite" />
+ </div>
+ </div>
+ </form>
+
+ <p tal:condition="not:view/isSite">XXX perhaps list locally
+ registered comonents here, or just give some stats about locally
+ registered objects with links to pages who actually show them...
+ XXX</p>
+
+ </div>
+ </body>
+
+</html>
Property changes on: Products.Five/branches/philikon-local-components/component/components.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Products.Five/branches/philikon-local-components/component/configure.zcml
===================================================================
--- Products.Five/branches/philikon-local-components/component/configure.zcml 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/component/configure.zcml 2006-03-01 00:34:35 UTC (rev 65631)
@@ -0,0 +1,32 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser">
+
+ <browser:page
+ for="OFS.interfaces.IObjectManager"
+ name="components.html"
+ class=".browser.ComponentsView"
+ template="components.pt"
+ permission="five.ManageSite"
+ />
+
+ <browser:pages
+ for="OFS.interfaces.ISimpleItem"
+ class=".browser.CustomizationView"
+ permission="five.ManageSite">
+
+ <browser:page
+ name="templateviews.html"
+ template="templateviews.pt"
+ />
+ <browser:page
+ name="customizeview.html"
+ template="customizeview.pt"
+ />
+ <browser:page
+ name="customizetemplate"
+ attribute="customizeTemplate"
+ />
+
+ </browser:pages>
+
+</configure>
Property changes on: Products.Five/branches/philikon-local-components/component/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Products.Five/branches/philikon-local-components/component/customizeview.pt
===================================================================
--- Products.Five/branches/philikon-local-components/component/customizeview.pt 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/component/customizeview.pt 2006-03-01 00:34:35 UTC (rev 65631)
@@ -0,0 +1,25 @@
+<html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
+ <body>
+ <div metal:fill-slot="body">
+
+ <p i18n:translate="">This is the source of the
+ <code tal:content="request/form/viewname">viewname</code>:</p>
+
+ <pre tal:content="python:view.templateSource(request.form['viewname'])">
+ template source
+ </pre>
+
+ <form action="." action="customizeTemplate" method="post"
+ enctype="multipart/form-data">
+
+ <input type="hidden" name="viewname" value="theviewname"
+ tal:attributes="value request/form/viewname" />
+ <input type="submit" name="" value="Customize" />
+
+ </form>
+
+ </div>
+ </body>
+
+</html>
Property changes on: Products.Five/branches/philikon-local-components/component/customizeview.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Products.Five/branches/philikon-local-components/component/interfaces.py
===================================================================
--- Products.Five/branches/philikon-local-components/component/interfaces.py 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/component/interfaces.py 2006-03-01 00:34:35 UTC (rev 65631)
@@ -0,0 +1,22 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Component interfaces
+
+$Id$
+"""
+from zope.app.component.interfaces import ISite
+from OFS.interfaces import IObjectManager
+
+class IObjectManagerSite(IObjectManager, ISite):
+ """Object manager that is also a site."""
Property changes on: Products.Five/branches/philikon-local-components/component/interfaces.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Products.Five/branches/philikon-local-components/component/templateviews.pt
===================================================================
--- Products.Five/branches/philikon-local-components/component/templateviews.pt 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/component/templateviews.pt 2006-03-01 00:34:35 UTC (rev 65631)
@@ -0,0 +1,22 @@
+<html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
+ <body>
+ <div metal:fill-slot="body">
+
+ <p i18n:translate="">Template-based (global) browser views available
+ for this component:</p>
+
+ <ul>
+ <li tal:repeat="reg view/templateViewRegistrations">
+ <a href=""
+ tal:attributes="href string:@@customize.html?viewname=${reg/name}"
+ tal:content="reg/name">
+ </a>
+ as defined in <tal:var replace="reg/info/filename" />.
+ </li>
+ </ul>
+
+ </div>
+ </body>
+
+</html>
Property changes on: Products.Five/branches/philikon-local-components/component/templateviews.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Products.Five/branches/philikon-local-components/component/tests.py
===================================================================
--- Products.Five/branches/philikon-local-components/component/tests.py 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/component/tests.py 2006-03-01 00:34:35 UTC (rev 65631)
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Component tests
+
+$Id$
+"""
+import unittest
+from zope.testing.doctestunit import DocFileSuite
+
+__docformat__ = "reStructuredText"
+
+def test_suite():
+ return unittest.TestSuite([
+ DocFileSuite('component.txt', package="Products.Five.component")
+ ])
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: Products.Five/branches/philikon-local-components/component/tests.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Products.Five/branches/philikon-local-components/site/browser.py
===================================================================
--- Products.Five/branches/philikon-local-components/site/browser.py 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/site/browser.py 2006-03-01 00:34:35 UTC (rev 65631)
@@ -19,8 +19,7 @@
from zope.app.component.hooks import clearSite
from Products.Five.browser import BrowserView
-from Products.Five.site.localsite import enableLocalSiteHook, \
- disableLocalSiteHook
+from Products.Five.component import enableSite, disableSite
class LocalSiteView(BrowserView):
"""View for convering a possible site to a site
@@ -41,7 +40,7 @@
if self.isSite():
raise ValueError('This is already a site')
- enableLocalSiteHook(self.context)
+ enableSite(self.context)
return "This object is now a site"
def unmakeSite(self):
@@ -49,7 +48,7 @@
if not self.isSite():
raise ValueError('This is not a site')
- disableLocalSiteHook(self.context)
+ disableSite(self.context)
# disableLocalSiteHook circumcised our context so that it's
# not an ISite anymore. That can mean that certain things for
Modified: Products.Five/branches/philikon-local-components/site/localsite.py
===================================================================
--- Products.Five/branches/philikon-local-components/site/localsite.py 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/site/localsite.py 2006-03-01 00:34:35 UTC (rev 65631)
@@ -15,27 +15,14 @@
$Id$
"""
-from zope.event import notify
-from zope.interface import directlyProvides, directlyProvidedBy
from zope.interface import implements
from zope.component import getGlobalSiteManager
from zope.component.exceptions import ComponentLookupError
-
from zope.app.component.interfaces import ISite, IPossibleSite
-from zope.app.publication.zopepublication import BeforeTraverseEvent
-from ExtensionClass import Base
-from Acquisition import aq_base, aq_inner, aq_parent
-from Products.SiteAccess.AccessRule import AccessRule
-from ZPublisher.BeforeTraverse import registerBeforeTraverse
-from ZPublisher.BeforeTraverse import unregisterBeforeTraverse
-
+from Acquisition import aq_inner, aq_parent
from Products.Five.site.interfaces import IFiveSiteManager, IFiveUtilityRegistry
-# Hook up custom component architecture calls
-import zope.app.component.hooks
-zope.app.component.hooks.setHooks()
-
def siteManagerAdapter(ob):
"""An adapter * -> ISiteManager.
@@ -52,41 +39,6 @@
# return the global site
return getGlobalSiteManager()
-HOOK_NAME = '__local_site_hook__'
-
-class LocalSiteHook(Base):
- def __call__(self, container, request):
- notify(BeforeTraverseEvent(container, request))
-
-
-def enableLocalSiteHook(obj):
- """Install __before_traverse__ hook for Local Site
- """
- # We want the original object, not stuff in between, and no acquisition
- obj = aq_base(obj)
- if not IPossibleSite.providedBy(obj):
- raise TypeError, 'Must provide IPossibleSite'
- hook = AccessRule(HOOK_NAME)
- registerBeforeTraverse(obj, hook, HOOK_NAME, 1)
-
- if not hasattr(obj, HOOK_NAME):
- setattr(obj, HOOK_NAME, LocalSiteHook())
-
- directlyProvides(obj, ISite, directlyProvidedBy(obj))
-
-def disableLocalSiteHook(obj):
- """Remove __before_traverse__ hook for Local Site
- """
- # We want the original object, not stuff in between, and no acquisition
- obj = aq_base(obj)
- if not ISite.providedBy(obj):
- raise TypeError, 'Must provide ISite'
- unregisterBeforeTraverse(obj, HOOK_NAME)
- if hasattr(obj, HOOK_NAME):
- delattr(obj, HOOK_NAME)
-
- directlyProvides(obj, directlyProvidedBy(obj) - ISite)
-
class FiveSiteManager(object):
implements(IFiveSiteManager)
Modified: Products.Five/branches/philikon-local-components/site/tests/sitemanager.txt
===================================================================
--- Products.Five/branches/philikon-local-components/site/tests/sitemanager.txt 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/site/tests/sitemanager.txt 2006-03-01 00:34:35 UTC (rev 65631)
@@ -30,8 +30,8 @@
Let's make the possible site a real site:
- >>> from Products.Five.site.localsite import enableLocalSiteHook
- >>> enableLocalSiteHook(dummysite)
+ >>> from Products.Five.component import enableSite
+ >>> enableSite(dummysite)
and tell Zope 3 about it:
@@ -118,7 +118,7 @@
Now we set the current site to the ``subsite``:
- >>> enableLocalSiteHook(subsite)
+ >>> enableSite(subsite)
>>> setSite(subsite)
When we call getServices() now, we get the correct site manager:
Modified: Products.Five/branches/philikon-local-components/site/tests/test_utility.py
===================================================================
--- Products.Five/branches/philikon-local-components/site/tests/test_utility.py 2006-03-01 00:04:15 UTC (rev 65630)
+++ Products.Five/branches/philikon-local-components/site/tests/test_utility.py 2006-03-01 00:34:35 UTC (rev 65631)
@@ -34,8 +34,8 @@
import Products.Five
from Products.Five import zcml
+from Products.Five.component import enableSite
from Products.Five.site.interfaces import IRegisterUtilitySimply
-from Products.Five.site.localsite import enableLocalSiteHook
from Products.Five.site.tests.dummy import manage_addDummySite, \
IDummyUtility, ISuperDummyUtility, DummyUtility
@@ -52,7 +52,7 @@
class="Products.Five.site.tests.dummy.DummySite" />"""
zcml.load_string(zcml_text)
manage_addDummySite(self.folder, 'site')
- enableLocalSiteHook(self.folder.site)
+ enableSite(self.folder.site)
setSite(self.folder.site)
# Hook up custom component architecture calls; we need to do
@@ -173,7 +173,7 @@
# let's also create a subsite and make that our site
manage_addDummySite(self.folder.site, 'subsite')
- enableLocalSiteHook(self.folder.site.subsite)
+ enableSite(self.folder.site.subsite)
setSite(self.folder.site.subsite)
# we should still be able to lookup the original utility from
@@ -249,7 +249,7 @@
# test local site vs. nested local site
manage_addDummySite(self.folder.site, 'subsite')
- enableLocalSiteHook(self.folder.site.subsite)
+ enableSite(self.folder.site.subsite)
setSite(self.folder.site.subsite)
sublocal_dummy = DummyUtility()
More information about the Zope-Checkins
mailing list