[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/folder/ Added an
ISublocations adapter to support dispatch of location events
Jim Fulton
jim at zope.com
Tue Jun 1 06:56:40 EDT 2004
Log message for revision 25145:
Added an ISublocations adapter to support dispatch of location events
to site managers as well as items.
-=-
Modified: Zope3/trunk/src/zope/app/folder/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/folder/configure.zcml 2004-06-01 10:53:56 UTC (rev 25144)
+++ Zope3/trunk/src/zope/app/folder/configure.zcml 2004-06-01 10:56:39 UTC (rev 25145)
@@ -45,6 +45,11 @@
permission="zope.View"
/>
+ <adapter
+ provides="zope.app.location.interfaces.ISublocations"
+ for=".interfaces.IFolder"
+ factory=".folder.FolderSublocations"
+ />
<!-- include browser package -->
Modified: Zope3/trunk/src/zope/app/folder/folder.py
===================================================================
--- Zope3/trunk/src/zope/app/folder/folder.py 2004-06-01 10:53:56 UTC (rev 25144)
+++ Zope3/trunk/src/zope/app/folder/folder.py 2004-06-01 10:56:39 UTC (rev 25145)
@@ -15,18 +15,15 @@
$Id$
"""
+from BTrees.OOBTree import OOBTree
+from interfaces import IFolder, IRootFolder
from persistent import Persistent
-from BTrees.OOBTree import OOBTree
+from zope.app.container.contained import Contained, setitem, uncontained
+from zope.app.site.interfaces import ISite
+from zope.app.site.servicecontainer import ServiceManagerContainer
from zope.exceptions import DuplicationError
from zope.interface import implements, directlyProvides
-from zope.app.container.contained import Contained, setitem, uncontained
-from zope.app.site.servicecontainer import ServiceManagerContainer
-
-from interfaces import IFolder, IRootFolder
-
-__metaclass__ = type
-
class Folder(Persistent, ServiceManagerContainer, Contained):
"""The standard Zope Folder implementation.
"""
@@ -109,3 +106,46 @@
f = Folder()
directlyProvides(f, IRootFolder)
return f
+
+class FolderSublocations(object):
+ """Get the sublocations of a folder
+
+ The subobjects of a folder include it's contents and it's service
+ manager if it is a site.
+
+ >>> folder = Folder()
+ >>> folder['ob1'] = Contained()
+ >>> folder['ob2'] = Contained()
+ >>> folder['ob3'] = Contained()
+ >>> subs = list(FolderSublocations(folder).sublocations())
+ >>> subs.remove(folder['ob1'])
+ >>> subs.remove(folder['ob2'])
+ >>> subs.remove(folder['ob3'])
+ >>> subs
+ []
+
+ >>> sm = Contained()
+ >>> from zope.component.interfaces import IServiceService
+ >>> directlyProvides(sm, IServiceService)
+ >>> folder.setSiteManager(sm)
+ >>> directlyProvides(folder, ISite)
+ >>> subs = list(FolderSublocations(folder).sublocations())
+ >>> subs.remove(folder['ob1'])
+ >>> subs.remove(folder['ob2'])
+ >>> subs.remove(folder['ob3'])
+ >>> subs.remove(sm)
+ >>> subs
+ []
+
+ """
+
+ def __init__(self, folder):
+ self.folder = folder
+
+ def sublocations(self):
+ folder = self.folder
+ for key in folder:
+ yield folder[key]
+
+ if ISite.providedBy(folder):
+ yield folder.getSiteManager()
Modified: Zope3/trunk/src/zope/app/folder/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/folder/tests.py 2004-06-01 10:53:56 UTC (rev 25144)
+++ Zope3/trunk/src/zope/app/folder/tests.py 2004-06-01 10:56:39 UTC (rev 25145)
@@ -54,9 +54,13 @@
ztapi.provideAdapter(IFolder, IZopeDublinCore, ZDCAnnotatableAdapter)
def test_suite():
+ from zope.testing.doctestunit import DocTestSuite
+ from zope.app.tests.placelesssetup import setUp, tearDown
return TestSuite((
makeSuite(Test),
makeSuite(FolderMetaDataTest),
+ DocTestSuite('zope.app.folder.folder',
+ setUp=setUp, tearDown=tearDown),
))
if __name__=='__main__':
More information about the Zope3-Checkins
mailing list