Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
plone.portlets.retriever.PortletRetriever Class Reference
Inheritance diagram for plone.portlets.retriever.PortletRetriever:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def getPortlets

Public Attributes

 context
 storage

Detailed Description

The default portlet retriever.

This will examine the context and its parents for contextual portlets,
provided they provide ILocalPortletAssignable.

Definition at line 16 of file retriever.py.


Constructor & Destructor Documentation

def plone.portlets.retriever.PortletRetriever.__init__ (   self,
  context,
  storage 
)

Reimplemented in plone.portlets.retriever.PlacelessPortletRetriever.

Definition at line 26 of file retriever.py.

00026 
00027     def __init__(self, context, storage):
00028         self.context = context
00029         self.storage = storage

Here is the caller graph for this function:


Member Function Documentation

Work out which portlets to display, returning a list of dicts
describing assignments to render.

Reimplemented in plone.portlets.retriever.PlacelessPortletRetriever.

Definition at line 30 of file retriever.py.

00030 
00031     def getPortlets(self):
00032         """Work out which portlets to display, returning a list of dicts
00033         describing assignments to render.
00034         """
00035         
00036         pcontext = IPortletContext(self.context, None)
00037         if pcontext is None:
00038             return []
00039             
00040         # Holds a list of (category, key, assignment).
00041         categories = [] 
00042         
00043         # Keeps track of the blacklisting status for global categores 
00044         # (user, group, content type). The status is either True (blocked)
00045         # or False (not blocked).
00046         blacklisted = {}
00047                 
00048         # This is the name of the manager (column) we're rendering
00049         manager = self.storage.__name__
00050         
00051         # 1. Fetch blacklisting status for each global category
00052 
00053         # First, find out which categories we will need to determine
00054         # blacklist status for
00055         
00056         for category, key in pcontext.globalPortletCategories(False):
00057             blacklisted[category] = None
00058         
00059         # Then walk the content hierarchy to find out what blacklist status
00060         # was assigned. Note that the blacklist is tri-state; if it's None it
00061         # means no assertion has been made (i.e. the category has neither been
00062         # whitelisted or blacklisted by this object or any parent). The first
00063         # item to give either a blacklisted (True) or whitelisted (False)
00064         # value for a given item will set the appropriate value. Parents of
00065         # this item that also set a black- or white-list value will then be
00066         # ignored.
00067 
00068         # Whilst walking the hierarchy, we also collect parent portlets, 
00069         # until we hit the first block.
00070 
00071         current = self.context
00072         currentpc = pcontext
00073         blacklistFetched = set()
00074         parentsBlocked = False
00075         
00076         while current is not None and currentpc is not None:
00077             assignable = ILocalPortletAssignable(current, None)
00078             if assignable is not None:
00079                 annotations = IAnnotations(assignable)
00080                 
00081                 if not parentsBlocked:
00082                     local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
00083                     if local is not None:
00084                         localManager = local.get(manager, None)
00085                         if localManager is not None:
00086                             categories.extend([(CONTEXT_CATEGORY, currentpc.uid, a) for a in localManager.values()])
00087 
00088                 blacklistStatus = annotations.get(CONTEXT_BLACKLIST_STATUS_KEY, {}).get(manager, None)
00089                 if blacklistStatus is not None:
00090                     for cat, status in blacklistStatus.items():
00091                         if cat == CONTEXT_CATEGORY:
00092                             if not parentsBlocked and status == True:
00093                                 parentsBlocked = True
00094                         else: # global portlet categories
00095                             if blacklisted.get(cat, False) is None:
00096                                 blacklisted[cat] = status
00097                             if status is not None:
00098                                 blacklistFetched.add(cat)
00099                                 
00100             # We can abort if parents are blocked and we've fetched all
00101             # blacklist statuses
00102             
00103             if parentsBlocked and len(blacklistFetched) == len(blacklisted):
00104                 break
00105                     
00106             # Check the parent - if there is no parent, we will stop
00107             current = currentpc.getParent()
00108             if current is not None:
00109                 currentpc = IPortletContext(current, None)
00110         
00111         # Get all global mappings for non-blacklisted categories
00112         
00113         for category, key in pcontext.globalPortletCategories(False):
00114             if not blacklisted[category]:
00115                 mapping = self.storage.get(category, None)
00116                 if mapping is not None:
00117                     for a in mapping.get(key, {}).values():
00118                         categories.append((category, key, a,))
00119         
00120         assignments = []
00121         for category, key, assignment in categories:
00122             assignments.append({'category'    : category,
00123                                 'key'         : key,
00124                                 'name'        : assignment.__name__,
00125                                 'assignment'  : assignment
00126                                 })
00127         return assignments
        

Here is the call graph for this function:


Member Data Documentation

Reimplemented in plone.portlets.retriever.PlacelessPortletRetriever.

Definition at line 27 of file retriever.py.

Reimplemented in plone.portlets.retriever.PlacelessPortletRetriever.

Definition at line 28 of file retriever.py.


The documentation for this class was generated from the following file: