Back to index

plone3  3.1.7
assignable.py
Go to the documentation of this file.
00001 from zope.interface import implementer
00002 from zope.component import adapter
00003 from zope.annotation.interfaces import IAnnotations
00004 
00005 from plone.portlets.interfaces import IPortletAssignmentMapping
00006 from plone.portlets.interfaces import ILocalPortletAssignable
00007 from plone.portlets.interfaces import IPortletManager
00008 
00009 from plone.portlets.constants import CONTEXT_ASSIGNMENT_KEY
00010 from plone.portlets.constants import CONTEXT_CATEGORY
00011 
00012 from BTrees.OOBTree import OOBTree
00013 
00014 from plone.app.portlets.storage import PortletAssignmentMapping
00015 
00016 @adapter(ILocalPortletAssignable, IPortletManager)
00017 @implementer(IPortletAssignmentMapping)
00018 def localPortletAssignmentMappingAdapter(context, manager):
00019     """Zope 2 version of the localPortletAssignmentMappingAdapter factory.
00020     """
00021     annotations = IAnnotations(context)
00022     local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
00023     if local is None:
00024         local = annotations[CONTEXT_ASSIGNMENT_KEY] = OOBTree()
00025     portlets = local.get(manager.__name__, None)
00026     if portlets is None:
00027         portlets = local[manager.__name__] = PortletAssignmentMapping(manager=manager.__name__,
00028                                                                       category=CONTEXT_CATEGORY)
00029 
00030     # XXX: For graceful migration
00031     if not getattr(portlets, '__manager__', ''):
00032         portlets.__manager__ = manager.__name__
00033     if not getattr(portlets, '__category__', ''):
00034         portlets.__category__ = CONTEXT_CATEGORY
00035     
00036     return portlets