Back to index

plone3  3.1.7
container.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 from zope.app.container.interfaces import IContainer
00003 from zope.app.container.contained import Contained
00004 
00005 from Products.CMFCore.PortalContent import PortalContent
00006 from Products.CMFCore.PortalFolder import PortalFolderBase
00007 from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
00008 from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
00009 
00010 from plone.app.content.interfaces import IReindexOnModify
00011 
00012 class OFSContainer(object):
00013     """A folder that's also a container.
00014     
00015     Borrowed in part from megrok.five.
00016     """
00017     
00018     implements(IContainer)
00019     
00020     isPrincipiaFolderish = 1
00021     
00022     def __init__(self, id=None):
00023         if id is not None:
00024             self.id = id
00025 
00026     # fulfill IContainer interface
00027 
00028     def keys(self):
00029         return self.objectIds()
00030 
00031     def values(self):
00032         return self.objectValues()
00033 
00034     def items(self):
00035         return self.objectItems()
00036 
00037     def get(self, name, default=None):
00038         return getattr(self, name, default)
00039 
00040     # __getitem__ is already implemented by ObjectManager
00041 
00042     def __setitem__(self, name, obj):
00043         name = name.encode('ascii') # may raise if there's a bugus id
00044         self._setObject(name, obj)
00045 
00046     def __delitem__(self, name):
00047         self.manage_delObjects([name])
00048 
00049     def __contains__(self, name):
00050         return self.hasObject(name)
00051 
00052     def __iter__(self):
00053         return iter(self.objectIds())
00054 
00055     def __len__(self):
00056         return len(self.objectIds())
00057         
00058 # Notes on this insane mixing of classes:
00059 # 
00060 #  - OFSContainer gives us Zope3-like container operations, and we want that
00061 #       to take priority so it comes first
00062 #  - CMFCatalogAware gives us catalog functionality. So does PortalContent,
00063 #       but PortalFolderBase overrides indexObject() and friends to do 
00064 #       nothing.
00065 #  - PortalFolderBase gives folder-like behaviour. It needs to come before
00066 #       PortalContent, otherwise objectIds() and friends don't work
00067 #  - PortalContent gives us SearchableText and WebDAV
00068 #  - DublinCoreImpl gives us DC fields
00069 #  - Contained gives us Zope3-like containment
00070 # 
00071 # ... I WANT AN ADAPTER!
00072         
00073 class Container(OFSContainer, CMFCatalogAware, PortalFolderBase, PortalContent, DefaultDublinCoreImpl, Contained):
00074     """A base class mixing in CMFish, contentish, containerish, containedish,
00075     dublincoreish behaviour.
00076     """
00077     
00078     implements(IReindexOnModify)
00079     
00080     def __init__(self, id=None, **kwargs):
00081         OFSContainer.__init__(self, id, **kwargs)
00082         PortalFolderBase.__init__(self, id, **kwargs)
00083         DefaultDublinCoreImpl.__init__(self, **kwargs)
00084         
00085         if id is not None:
00086             self.id = id