Back to index

plone3  3.1.7
traversal.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 from zope.component import adapts, getUtility, getMultiAdapter
00003 
00004 from zope.traversing.interfaces import ITraversable
00005 from zope.publisher.interfaces.http import IHTTPRequest
00006 
00007 from plone.portlets.interfaces import ILocalPortletAssignable
00008 from plone.portlets.interfaces import IPortletManager
00009 from plone.portlets.interfaces import IPortletAssignmentMapping
00010 
00011 from Products.CMFCore.interfaces import ISiteRoot
00012 
00013 from plone.portlets.constants import USER_CATEGORY
00014 from plone.portlets.constants import GROUP_CATEGORY
00015 from plone.portlets.constants import CONTENT_TYPE_CATEGORY
00016 
00017 from plone.app.portlets.storage import PortletAssignmentMapping
00018 from plone.app.portlets.storage import UserPortletAssignmentMapping
00019 
00020 class ContextPortletNamespace(object):
00021     """Used to traverse to a contextual portlet assignable
00022     """
00023     implements(ITraversable)
00024     adapts(ILocalPortletAssignable, IHTTPRequest)
00025     
00026     def __init__(self, context, request=None):
00027         self.context = context
00028         self.request = request
00029         
00030     def traverse(self, name, ignore):
00031         column = getUtility(IPortletManager, name=name)
00032         manager = getMultiAdapter((self.context, column,), IPortletAssignmentMapping)
00033         return manager
00034 
00035 class DashboardNamespace(object):
00036     """Used to traverse to a portlet assignable for the current user for
00037     the dashboard.
00038     """
00039     implements(ITraversable)
00040     adapts(ISiteRoot, IHTTPRequest)
00041     
00042     def __init__(self, context, request=None):
00043         self.context = context
00044         self.request = request
00045         
00046     def traverse(self, name, ignore):
00047         col, user = name.split('+')
00048         column = getUtility(IPortletManager, name=col)
00049         category = column[USER_CATEGORY]
00050         manager = category.get(user, None)
00051         if manager is None:
00052             manager = category[user] = UserPortletAssignmentMapping(manager=col,
00053                                                                     category=USER_CATEGORY,
00054                                                                     name=user)
00055                                                                             
00056         # XXX: For graceful migration
00057         if not getattr(manager, '__manager__', None):
00058             manager.__manager__ = col
00059         if not getattr(manager, '__category__', None):
00060             manager.__category__ = USER_CATEGORY
00061         if not getattr(manager, '__name__', None):
00062             manager.__name__ = user
00063         
00064         return manager
00065 
00066 class GroupPortletNamespace(object):
00067     """Used to traverse to a group portlet assignable
00068     """
00069     implements(ITraversable)
00070     adapts(ISiteRoot, IHTTPRequest)
00071     
00072     def __init__(self, context, request=None):
00073         self.context = context
00074         self.request = request
00075         
00076     def traverse(self, name, ignore):
00077         col, group = name.split('+')
00078         column = getUtility(IPortletManager, name=col)
00079         category = column[GROUP_CATEGORY]
00080         manager = category.get(group, None)
00081         if manager is None:
00082             manager = category[group] = PortletAssignmentMapping(manager=col,
00083                                                                  category=GROUP_CATEGORY,
00084                                                                  name=group)
00085         
00086         # XXX: For graceful migration
00087         if not getattr(manager, '__manager__', None):
00088             manager.__manager__ = col
00089         if not getattr(manager, '__category__', None):
00090             manager.__category__ = GROUP_CATEGORY
00091         if not getattr(manager, '__name__', None):
00092             manager.__name__ = group
00093         
00094         return manager
00095 
00096 class ContentTypePortletNamespace(object):
00097     """Used to traverse to a content type portlet assignable
00098     """
00099     implements(ITraversable)
00100     adapts(ISiteRoot, IHTTPRequest)
00101     
00102     def __init__(self, context, request=None):
00103         self.context = context
00104         self.request = request
00105         
00106     def traverse(self, name, ignore):
00107         col, pt = name.split('+')
00108         column = getUtility(IPortletManager, name=col)
00109         category = column[CONTENT_TYPE_CATEGORY]
00110         manager = category.get(pt, None)
00111         if manager is None:
00112             manager = category[pt] = PortletAssignmentMapping(manager=col,
00113                                                               category=CONTENT_TYPE_CATEGORY,
00114                                                               name=pt)
00115         
00116         # XXX: For graceful migration
00117         if not getattr(manager, '__manager__', None):
00118             manager.__manager__ = col
00119         if not getattr(manager, '__category__', None):
00120             manager.__category__ = CONTENT_TYPE_CATEGORY
00121         if not getattr(manager, '__name__', None):
00122             manager.__name__ = pt
00123         
00124         return manager