Back to index

plone3  3.1.7
__init__.py
Go to the documentation of this file.
00001 from Acquisition import aq_base
00002 from zope.component.globalregistry import base
00003 from zope.traversing.interfaces import IContainmentRoot
00004 from zope.app.component.interfaces import ISite
00005 from five.localsitemanager.registry import PersistentComponents
00006 from five.localsitemanager.utils import get_parent
00007 from Products.Five.component.interfaces import IObjectManagerSite
00008 from Products.Five.component import enableSite
00009 
00010 
00011 def make_site(obj, iface=ISite):
00012     """Give the specified object required qualities to identify it as a proper
00013     ISite.
00014     """
00015     if ISite.providedBy(obj):
00016         raise ValueError('This is already a site')
00017     
00018     next = find_next_sitemanager(obj)
00019     if next is None:
00020         next = base
00021 
00022     enableSite(obj, iface=iface)
00023 
00024     name = 'five'
00025     path = getattr(obj, 'getPhysicalPath', None)
00026     if path is not None and callable(path):
00027         name = '/'.join(path())
00028 
00029     components = PersistentComponents(name=name, bases=(next,))
00030     obj.setSiteManager(components)
00031     components.__parent__ = aq_base(obj)
00032 
00033 
00034 def make_objectmanager_site(obj):
00035     """Just a bit of sugar coating to make an unnofficial objectmanager
00036     based site.
00037     """
00038     make_site(obj, IObjectManagerSite)
00039 
00040 
00041 def find_next_sitemanager(site):
00042     """Find the closest sitemanager that is not the specified site's
00043     sitemanager.
00044     """
00045     container = site
00046     sm = None
00047     while sm is None:
00048         if IContainmentRoot.providedBy(container):
00049             # We are at the root site, return None
00050             return None
00051 
00052         try:
00053             container = get_parent(container)
00054             if container is None:
00055                 return None
00056         except TypeError:
00057             # There was not enough context; probably run from a test
00058             return None
00059 
00060         if ISite.providedBy(container):
00061             sm = container.getSiteManager()
00062     return sm
00063 
00064 
00065 def update_sitemanager_bases(site):
00066     """Formulate the most appropriate __bases__ value for a site's site manager
00067     by asking find_next_sitemanager what the next appropriate site manager
00068     is.  After this call, the __bases__ is guaranteed to have one and only
00069     one value in the __bases__ list/tuple.
00070     """
00071     next = find_next_sitemanager(site)
00072     if next is None:
00073         next = base
00074     sm = site.getSiteManager()
00075     sm.__bases__ = (next, )
00076 
00077 
00078 def update_sitemanager_bases_handler(site, event):
00079     update_sitemanager_bases(site)