예제 #1
0
    def global_portlets(self, category, prefix):
        """ Return the list of global portlets from a given category for the current context.

        Invisible (hidden) portlets are excluded.

        """
        context = aq_inner(self.context)

        # get the portlet context
        pcontext = IPortletContext(self.context)

        portal_state = getMultiAdapter((context, self.request),
                                       name=u'plone_portal_state')  # noqa
        base_url = portal_state.portal_url()

        portlets = []
        for cat, key in pcontext.globalPortletCategories(False):
            if cat == category:
                mapping = self.manager.get(category, None)
                assignments = []
                if mapping is not None:
                    is_visible = lambda a: IPortletAssignmentSettings(a).get(
                        'visible', True)  # noqa
                    assignments.extend([
                        a for a in mapping.get(key, {}).values()
                        if is_visible(a)
                    ])
                if assignments:
                    edit_url = '%s/++%s++%s+%s' % (base_url, prefix,
                                                   self.manager.__name__, key)
                    portlets.extend(
                        self.portlets_for_assignments(assignments,
                                                      self.manager, edit_url))

        return portlets
예제 #2
0
    def global_portlets(self, category, prefix):
        """ Return the list of global portlets from a given category for the current context.

        Invisible (hidden) portlets are excluded.

        """
        context = aq_inner(self.context)

        # get the portlet context
        pcontext = IPortletContext(self.context)

        portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state')
        base_url = portal_state.portal_url()

        portlets = []
        for cat, key in pcontext.globalPortletCategories(False):
            if cat == category:
                mapping = self.manager.get(category, None)
                assignments = []
                if mapping is not None:
                    is_visible = lambda a: IPortletAssignmentSettings(a).get('visible', True)
                    assignments.extend([a for a in mapping.get(key, {}).values() if is_visible(a)])
                if assignments:
                    edit_url = '%s/++%s++%s+%s' % (base_url, prefix, self.manager.__name__, key)
                    portlets.extend(self.portlets_for_assignments(assignments, self.manager, edit_url))

        return portlets
예제 #3
0
 def testAnonymous(self):
     self.logout()
     ctx = IPortletContext(self.portal)
     g = ctx.globalPortletCategories()
     self.assertEqual(len(g), 2)
     self.assertEqual(g[0], ('content_type', 'Plone Site'))
     self.assertEqual(g[1], ('user', 'Anonymous User'))
예제 #4
0
 def testAnonymous(self):
     self.logout()
     ctx = IPortletContext(self.folder)
     g = ctx.globalPortletCategories()
     self.assertEqual(len(g), 2)
     self.assertEqual(g[0], ('content_type', 'Folder'))
     self.assertEqual(g[1], ('user', 'Anonymous User'))
예제 #5
0
 def testAnonymous(self):
     logout()
     ctx = IPortletContext(self.folder)
     g = ctx.globalPortletCategories()
     self.assertEqual(len(g), 2)
     self.assertEqual(g[0], ('content_type', 'Folder'))
     self.assertEqual(g[1], ('user', 'Anonymous User'))
예제 #6
0
 def testAnonymous(self):
     logout()
     ctx = IPortletContext(self.portal)
     g = ctx.globalPortletCategories()
     self.assertEqual(len(g), 2)
     self.assertEqual(g[0], ('content_type', 'Plone Site'))
     self.assertEqual(g[1], ('user', 'Anonymous User'))
예제 #7
0
    def testGlobalsWithSingleGroup(self):

        group = self.portal.portal_groups.getGroupById('Reviewers')
        self.setRoles(('Manager', ))
        group.addMember(user_name)
        self.setRoles(('Member', ))

        ctx = IPortletContext(self.folder)
        g = ctx.globalPortletCategories()
        self.assertEqual(len(g), 4)
        self.assertEqual(g[0], ('content_type', 'Folder'))
        self.assertEqual(g[1], ('user', user_name))
        self.assertEqual(g[3], ('group', 'Reviewers'))
예제 #8
0
    def testGlobalsWithSingleGroup(self):

        group = self.portal.portal_groups.getGroupById('Reviewers')
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        group.addMember(user_name)
        setRoles(self.portal, TEST_USER_ID, ['Member'])

        ctx = IPortletContext(self.folder)
        g = ctx.globalPortletCategories()
        self.assertEqual(len(g), 4)
        self.assertEqual(g[0], ('content_type', 'Folder'))
        self.assertEqual(g[1], ('user', user_name))
        self.assertEqual(g[3], ('group', 'Reviewers'))
예제 #9
0
    def testGlobalsWithSingleGroup(self):

        group = self.portal.portal_groups.getGroupById('Reviewers')
        self.setRoles(('Manager', ))
        group.addMember(user_name)
        self.setRoles(('Member', ))

        ctx = IPortletContext(self.portal)
        g = ctx.globalPortletCategories()
        self.assertEqual(len(g), 4)
        self.assertEqual(g[0], ('content_type', 'Plone Site'))
        self.assertEqual(g[1], ('user', user_name))
        self.assertEqual(g[3], ('group', 'Reviewers'))
예제 #10
0
    def testGlobalsWithSingleGroup(self):

        group = self.portal.portal_groups.getGroupById('Reviewers')
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        group.addMember(user_name)
        setRoles(self.portal, TEST_USER_ID, ['Member'])

        ctx = IPortletContext(self.portal)
        g = ctx.globalPortletCategories()
        self.assertEqual(len(g), 4)
        self.assertEqual(g[0], ('content_type', 'Plone Site'))
        self.assertEqual(g[1], ('user', user_name))
        self.assertEqual(g[3], ('group', 'Reviewers'))
예제 #11
0
    def testGlobalsWithMultipleGroup(self):

        self.setRoles(('Manager', ))
        group = self.portal.portal_groups.getGroupById('Reviewers')
        group.addMember(user_name)
        group = self.portal.portal_groups.getGroupById('Administrators')
        group.addMember(user_name)
        self.setRoles(('Member', ))

        ctx = IPortletContext(self.folder)
        g = ctx.globalPortletCategories()
        self.assertEqual(len(g), 5)
        self.assertEqual(g[0], ('content_type', 'Folder'))
        self.assertEqual(g[1], ('user', user_name))
        self.assertEqual(g[2], ('group', 'Administrators'))
        self.assertEqual(g[4], ('group', 'Reviewers'))
예제 #12
0
    def testGlobalsWithMultipleGroup(self):

        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        group = self.portal.portal_groups.getGroupById('Reviewers')
        group.addMember(user_name)
        group = self.portal.portal_groups.getGroupById('Administrators')
        group.addMember(user_name)
        setRoles(self.portal, TEST_USER_ID, ['Member'])

        ctx = IPortletContext(self.folder)
        g = ctx.globalPortletCategories()
        self.assertEqual(len(g), 5)
        self.assertEqual(g[0], ('content_type', 'Folder'))
        self.assertEqual(g[1], ('user', user_name))
        self.assertEqual(g[2], ('group', 'Administrators'))
        self.assertEqual(g[4], ('group', 'Reviewers'))
예제 #13
0
    def testGlobalsWithMultipleGroup(self):

        self.setRoles(('Manager', ))
        group = self.portal.portal_groups.getGroupById('Reviewers')
        group.addMember(user_name)
        group = self.portal.portal_groups.getGroupById('Administrators')
        group.addMember(user_name)
        self.setRoles(('Member', ))

        ctx = IPortletContext(self.portal)
        g = ctx.globalPortletCategories()
        self.assertEquals(len(g), 5)
        self.assertEquals(g[0], ('content_type', 'Plone Site'))
        self.assertEquals(g[1], ('user', user_name))
        self.assertEquals(g[2], ('group', 'Administrators'))
        self.assertEquals(g[4], ('group', 'Reviewers'))
예제 #14
0
    def testGlobalsWithMultipleGroup(self):

        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        group = self.portal.portal_groups.getGroupById('Reviewers')
        group.addMember(TEST_USER_ID)
        group = self.portal.portal_groups.getGroupById('Administrators')
        group.addMember(TEST_USER_ID)
        setRoles(self.portal, TEST_USER_ID, ['Member'])

        ctx = IPortletContext(self.portal)
        g = ctx.globalPortletCategories()
        self.assertEqual(len(g), 5)
        self.assertEqual(g[0], ('content_type', 'Plone Site'))
        self.assertEqual(g[1], ('user', TEST_USER_ID))
        self.assertEqual(g[2], ('group', 'Administrators'))
        self.assertEqual(g[4], ('group', 'Reviewers'))
예제 #15
0
 def testGlobalsNoGroups(self):
     ctx = IPortletContext(self.portal)
     g = ctx.globalPortletCategories()
     self.assertEqual(len(g), 3)
     self.assertEqual(g[0], ('content_type', 'Plone Site'))
     self.assertEqual(g[1], ('user', user_name))
예제 #16
0
    def getPortlets(self):
        """Work out which portlets to display, returning a list of dicts
        describing assignments to render.
        """

        pcontext = IPortletContext(self.context, None)
        if pcontext is None:
            return []

        # Holds a list of (category, key, assignment).
        categories = []

        # Keeps track of the blacklisting status for global categores
        # (user, group, content type). The status is either True (blocked)
        # or False (not blocked).
        blacklisted = {}

        # This is the name of the manager (column) we're rendering
        manager = self.storage.__name__

        # 1. Fetch blacklisting status for each global category

        # First, find out which categories we will need to determine
        # blacklist status for

        for category, key in pcontext.globalPortletCategories(False):
            blacklisted[category] = None

        # Then walk the content hierarchy to find out what blacklist status
        # was assigned. Note that the blacklist is tri-state; if it's None it
        # means no assertion has been made (i.e. the category has neither been
        # whitelisted or blacklisted by this object or any parent). The first
        # item to give either a blacklisted (True) or whitelisted (False)
        # value for a given item will set the appropriate value. Parents of
        # this item that also set a black- or white-list value will then be
        # ignored.

        # Whilst walking the hierarchy, we also collect parent portlets,
        # until we hit the first block.

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False

        while current is not None and currentpc is not None:
            assignable = ILocalPortletAssignable(current, None)
            if assignable is not None:
                annotations = IAnnotations(assignable)

                if not parentsBlocked:
                    local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                    if local is not None:
                        localManager = local.get(manager, None)
                        if localManager is not None:
                            #categories.extend([(CONTEXT_CATEGORY, currentpc.uid, a) for a in localManager.values()]) #SV -
                            new_categories = [
                                (CONTEXT_CATEGORY, currentpc.uid, a)
                                for a in localManager.values()
                            ]  #SV +
                            categories = new_categories + categories  #SV +

                blacklistStatus = annotations.get(CONTEXT_BLACKLIST_STATUS_KEY,
                                                  {}).get(manager, None)
                if blacklistStatus is not None:
                    for cat, status in blacklistStatus.items():
                        if cat == CONTEXT_CATEGORY:
                            if not parentsBlocked and status == True:
                                parentsBlocked = True
                        else:  # global portlet categories
                            if blacklisted.get(cat, False) is None:
                                blacklisted[cat] = status
                            if status is not None:
                                blacklistFetched.add(cat)

            # We can abort if parents are blocked and we've fetched all
            # blacklist statuses

            if parentsBlocked and len(blacklistFetched) == len(blacklisted):
                break

            # Check the parent - if there is no parent, we will stop
            current = currentpc.getParent()
            if current is not None:
                currentpc = IPortletContext(current, None)

        # Get all global mappings for non-blacklisted categories

        for category, key in pcontext.globalPortletCategories(False):
            if not blacklisted[category]:
                mapping = self.storage.get(category, None)
                if mapping is not None:
                    for a in mapping.get(key, {}).values():
                        categories.append((
                            category,
                            key,
                            a,
                        ))

        assignments = []
        for category, key, assignment in categories:
            assignments.append({
                'category': category,
                'key': key,
                'name': assignment.__name__,
                'assignment': assignment
            })
        return assignments
    def getPortlets(self):

        portal_state = getMultiAdapter((self.context, self.context.REQUEST),
                                       name=u'plone_portal_state')
        portal = portal_state.portal()
        pcontext = IPortletContext(self.context, None)
        if pcontext is None:
            return []

        categories = []

        blacklisted = {}

        manager = self.storage.__name__

        for category, key in pcontext.globalPortletCategories(False):
            blacklisted[category] = None

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False

        while current is not None and currentpc is not None:
            if ILocalPortletAssignable.providedBy(current):
                assignable = current
            else:
                assignable = queryAdapter(current, ILocalPortletAssignable)

            if assignable is not None:
                if IAnnotations.providedBy(assignable):
                    annotations = assignable
                else:
                    annotations = queryAdapter(assignable, IAnnotations)

                if not parentsBlocked:
                    local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                    if local is not None:
                        localManager = local.get(manager, None)
                        if localManager is not None:
                            categories.extend([(CONTEXT_CATEGORY,
                                                currentpc.uid, a)
                                               for a in localManager.values()])

                blacklistStatus = annotations.get(CONTEXT_BLACKLIST_STATUS_KEY,
                                                  {}).get(manager, None)
                if blacklistStatus is not None:
                    for cat, status in blacklistStatus.items():
                        if cat == CONTEXT_CATEGORY:
                            if not parentsBlocked and status == True:
                                parentsBlocked = True
                        else:  # global portlet categories
                            if blacklisted.get(cat, False) is None:
                                blacklisted[cat] = status
                            if status is not None:
                                blacklistFetched.add(cat)

            if parentsBlocked and len(blacklistFetched) == len(blacklisted):
                break
            current = currentpc.getParent()
            if current is not None:
                if IPortletContext.providedBy(current):
                    currentpc = current
                else:
                    currentpc = queryAdapter(current, IPortletContext)

        for category, key in pcontext.globalPortletCategories(False):
            if not blacklisted[category]:
                mapping = self.storage.get(category, None)
                if mapping is not None:
                    for a in mapping.get(key, {}).values():
                        categories.append((
                            category,
                            key,
                            a,
                        ))

        managerUtility = getUtility(IPortletManager, manager, portal)

        here_url = '/'.join(aq_inner(self.context).getPhysicalPath())

        assignments = []
        for category, key, assignment in categories:
            assigned = ISolgemaPortletAssignment(assignment)
            portletHash = hashPortletInfo(
                dict(
                    manager=manager,
                    category=category,
                    key=key,
                    name=assignment.__name__,
                ))
            if not getattr(assigned, 'stopUrls', False) or len([
                    stopUrl for stopUrl in getattr(assigned, 'stopUrls', [])
                    if stopUrl in here_url
            ]) == 0:
                assignments.append({
                    'category':
                    category,
                    'key':
                    key,
                    'name':
                    assignment.__name__,
                    'assignment':
                    assignment,
                    'hash':
                    hashPortletInfo(
                        dict(
                            manager=manager,
                            category=category,
                            key=key,
                            name=assignment.__name__,
                        )),
                    'stopUrls':
                    ISolgemaPortletAssignment(assignment).stopUrls,
                })

        if hasattr(managerUtility, 'listAllManagedPortlets'):
            hashlist = managerUtility.listAllManagedPortlets
            assignments.sort(lambda a, b: cmp(
                hashlist.count(a['hash']) > 0 and hashlist.index(a['hash']
                                                                 ) or 0,
                hashlist.count(b['hash']) > 0 and hashlist.index(b['hash']) or
                0))

        return assignments
예제 #18
0
    def getManagedPortlets(self):
        """Work out which portlets to display, returning a list of dicts
        describing assignments to render.
        Bypass blacklist tests
        """
        portal_state = getMultiAdapter((self.context, self.context.REQUEST), name=u"plone_portal_state")
        portal = portal_state.portal()
        pcontext = IPortletContext(self.context, None)
        if pcontext is None:
            return []

        categories = []

        blacklisted = {}

        manager = self.storage.__name__

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False

        while current is not None and currentpc is not None:
            assignable = ILocalPortletAssignable(current, None)
            if assignable is not None:
                annotations = IAnnotations(assignable)
                local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                if local is not None:
                    localManager = local.get(manager, None)
                    if localManager is not None:
                        categories.extend([(CONTEXT_CATEGORY, currentpc.uid, a) for a in localManager.values()])

            # Check the parent - if there is no parent, we will stop
            current = currentpc.getParent()
            if current is not None:
                currentpc = IPortletContext(current, None)

        # Get all global mappings for non-blacklisted categories

        for category, key in pcontext.globalPortletCategories(False):
            mapping = self.storage.get(category, None)
            if mapping is not None:
                for a in mapping.get(key, {}).values():
                    categories.append((category, key, a))

        managerUtility = getUtility(IPortletManager, manager, portal)

        if not getattr(managerUtility, "listAllManagedPortlets", []):
            managerUtility.listAllManagedPortlets = []

        hashlist = getattr(managerUtility, "listAllManagedPortlets", [])
        assignments = []
        for category, key, assignment in categories:
            portletHash = hashPortletInfo(dict(manager=manager, category=category, key=key, name=assignment.__name__))
            if portletHash not in hashlist:
                hashlist.append(portletHash)
            try:
                assignments.append(
                    {
                        "category": category,
                        "key": key,
                        "name": assignment.__name__,
                        "assignment": assignment,
                        "hash": portletHash,
                        "stopUrls": ISolgemaPortletAssignment(assignment).stopUrls,
                        "manager": manager,
                    }
                )
            except TypeError:
                LOG.info(
                    u'Error while retrieving portlet assignment settings.\n\
                           Context: "%s", Category: "%s", Key: "%s", Assignment\n\
                           Class: "%s", Assignment ID: "%s"'
                    % (
                        "/".join(self.context.getPhysicalPath()),
                        category,
                        key,
                        str(assignment.__class__),
                        assignment.__name__,
                    ),
                    context=self.context,
                )

        managerUtility.listAllManagedPortlets = hashlist

        # order the portlets
        assignments.sort(lambda a, b: cmp(hashlist.index(a["hash"]), hashlist.index(b["hash"])))

        li = []
        here_url = "/".join(aq_inner(self.context).getPhysicalPath())
        for assigndict in assignments:
            stopped = False
            if (
                assigndict.has_key("stopUrls")
                and hasattr(assigndict["stopUrls"], "sort")
                and len(assigndict["stopUrls"]) > 0
            ):
                for stopUrl in assigndict["stopUrls"]:
                    if stopUrl in here_url:
                        stopped = True
            assigndict["stopped"] = stopped
            assigndict["here_url"] = here_url

        return assignments
예제 #19
0
 def testGlobalsNoGroups(self):
     ctx = IPortletContext(self.portal)
     g = ctx.globalPortletCategories()
     self.assertEqual(len(g), 3)
     self.assertEqual(g[0], ('content_type', 'Plone Site'))
     self.assertEqual(g[1], ('user', user_name))
예제 #20
0
    def getPortlets(self):

        portal_state = getMultiAdapter((self.context, self.context.REQUEST), name=u'plone_portal_state')
        portal = portal_state.portal()
        pcontext = IPortletContext(self.context, None)
        if pcontext is None:
            return []

        categories = [] 

        blacklisted = {}

        manager = self.storage.__name__

        for category, key in pcontext.globalPortletCategories(False):
            blacklisted[category] = None

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False
        
        while current is not None and currentpc is not None:
            if ILocalPortletAssignable.providedBy(current):
                assignable = current
            else:
                assignable = queryAdapter(current, ILocalPortletAssignable)

            if assignable is not None:
                if IAnnotations.providedBy(assignable):
                    annotations = assignable
                else:
                    annotations = queryAdapter(assignable, IAnnotations)
                
                if not parentsBlocked:
                    local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                    if local is not None:
                        localManager = local.get(manager, None)
                        if localManager is not None:
                            categories.extend([(CONTEXT_CATEGORY, currentpc.uid, a) for a in localManager.values()])

                blacklistStatus = annotations.get(CONTEXT_BLACKLIST_STATUS_KEY, {}).get(manager, None)
                if blacklistStatus is not None:
                    for cat, status in blacklistStatus.items():
                        if cat == CONTEXT_CATEGORY:
                            if not parentsBlocked and status == True:
                                parentsBlocked = True
                        else: # global portlet categories
                            if blacklisted.get(cat, False) is None:
                                blacklisted[cat] = status
                            if status is not None:
                                blacklistFetched.add(cat)

            if parentsBlocked and len(blacklistFetched) == len(blacklisted):
                break
            current = currentpc.getParent()
            if current is not None:
                if IPortletContext.providedBy(current):
                    currentpc = current
                else:
                    currentpc = queryAdapter(current, IPortletContext)

        for category, key in pcontext.globalPortletCategories(False):
            if not blacklisted[category]:
                mapping = self.storage.get(category, None)
                if mapping is not None:
                    for a in mapping.get(key, {}).values():
                        categories.append((category, key, a,))

        managerUtility = getUtility(IPortletManager, manager, portal)

        here_url = '/'.join(aq_inner(self.context).getPhysicalPath())

        assignments = []
        for category, key, assignment in categories:
            assigned = ISolgemaPortletAssignment(assignment)
            portletHash = hashPortletInfo(dict(manager=manager, category=category, key=key, name =assignment.__name__,))
            if not getattr(assigned, 'stopUrls', False) or len([stopUrl for stopUrl in getattr(assigned, 'stopUrls', []) if stopUrl in here_url])==0:
                assignments.append({'category'    : category,
                                    'key'         : key,
                                    'name'        : assignment.__name__,
                                    'assignment'  : assignment,
                                    'hash'        : hashPortletInfo(dict(manager=manager, category=category, key=key, name =assignment.__name__,)),
                                    'stopUrls'    : ISolgemaPortletAssignment(assignment).stopUrls,
                                    })
        
        if hasattr(managerUtility, 'listAllManagedPortlets'):
            hashlist = managerUtility.listAllManagedPortlets
            assignments.sort(lambda a,b:cmp(hashlist.count(a['hash'])>0 and hashlist.index(a['hash']) or 0, hashlist.count(b['hash'])>0 and hashlist.index(b['hash']) or 0))

        return assignments
예제 #21
0
 def testGlobalsNoGroups(self):
     ctx = IPortletContext(self.folder)
     g = ctx.globalPortletCategories()
     self.assertEqual(len(g), 3)
     self.assertEqual(g[0], ('content_type', 'Folder'))
     self.assertEqual(g[1], ('user', TEST_USER_ID))
    def getManagedPortlets(self):
        """Work out which portlets to display, returning a list of dicts
        describing assignments to render.
        Bypass blacklist tests
        """
        portal_state = getMultiAdapter((self.context, self.context.REQUEST),
                                       name=u'plone_portal_state')
        portal = portal_state.portal()
        pcontext = IPortletContext(self.context, None)
        if pcontext is None:
            return []

        categories = []

        blacklisted = {}

        manager = self.storage.__name__

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False

        while current is not None and currentpc is not None:
            assignable = ILocalPortletAssignable(current, None)
            if assignable is not None:
                annotations = IAnnotations(assignable)
                local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                if local is not None:
                    localManager = local.get(manager, None)
                    if localManager is not None:
                        categories.extend([(CONTEXT_CATEGORY, currentpc.uid, a)
                                           for a in localManager.values()])

            # Check the parent - if there is no parent, we will stop
            current = currentpc.getParent()
            if current is not None:
                currentpc = IPortletContext(current, None)

        # Get all global mappings for non-blacklisted categories

        for category, key in pcontext.globalPortletCategories(False):
            mapping = self.storage.get(category, None)
            if mapping is not None:
                for a in mapping.get(key, {}).values():
                    categories.append((
                        category,
                        key,
                        a,
                    ))

        managerUtility = getUtility(IPortletManager, manager, portal)

        if not getattr(managerUtility, 'listAllManagedPortlets', []):
            managerUtility.listAllManagedPortlets = []

        hashlist = getattr(managerUtility, 'listAllManagedPortlets', [])
        assignments = []
        for category, key, assignment in categories:
            portletHash = hashPortletInfo(
                dict(
                    manager=manager,
                    category=category,
                    key=key,
                    name=assignment.__name__,
                ))
            if portletHash not in hashlist:
                hashlist.append(portletHash)
            assignments.append({
                'category':
                category,
                'key':
                key,
                'name':
                assignment.__name__,
                'assignment':
                assignment,
                'hash':
                portletHash,
                'stopUrls':
                ISolgemaPortletAssignment(assignment).stopUrls,
                'manager':
                manager,
            })

        managerUtility.listAllManagedPortlets = hashlist

        #order the portlets
        assignments.sort(lambda a, b: cmp(hashlist.index(a['hash']),
                                          hashlist.index(b['hash'])))

        li = []
        here_url = '/'.join(aq_inner(self.context).getPhysicalPath())
        for assigndict in assignments:
            stopped = False
            if assigndict.has_key('stopUrls') and hasattr(
                    assigndict['stopUrls'],
                    'sort') and len(assigndict['stopUrls']) > 0:
                for stopUrl in assigndict['stopUrls']:
                    if stopUrl in here_url:
                        stopped = True
            assigndict['stopped'] = stopped
            assigndict['here_url'] = here_url

        return assignments
    def getManagedPortlets(self):
        """Work out which portlets to display, returning a list of dicts
        describing assignments to render.
        Bypass blacklist tests
        """
        portal_state = getMultiAdapter((self.context, self.context.REQUEST), name=u'plone_portal_state')
        portal = portal_state.portal()
        pcontext = IPortletContext(self.context, None)
        if pcontext is None:
            return []

        categories = [] 

        blacklisted = {}

        manager = self.storage.__name__

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False

        while current is not None and currentpc is not None:
            assignable = ILocalPortletAssignable(current, None)
            if assignable is not None:
                annotations = IAnnotations(assignable)
                local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                if local is not None:
                    localManager = local.get(manager, None)
                    if localManager is not None:
                        categories.extend([(CONTEXT_CATEGORY, currentpc.uid, a) for a in localManager.values()])
                    
            # Check the parent - if there is no parent, we will stop
            current = currentpc.getParent()
            if current is not None:
                currentpc = IPortletContext(current, None)
        
        # Get all global mappings for non-blacklisted categories
        
        for category, key in pcontext.globalPortletCategories(False):
            mapping = self.storage.get(category, None)
            if mapping is not None:
                for a in mapping.get(key, {}).values():
                    categories.append((category, key, a,))

        managerUtility = getUtility(IPortletManager, manager, portal)
        
        if not getattr(managerUtility, 'listAllManagedPortlets', []):
            managerUtility.listAllManagedPortlets = []

        hashlist = getattr(managerUtility, 'listAllManagedPortlets', [])
        assignments = []
        for category, key, assignment in categories:
            portletHash = hashPortletInfo(dict(manager=manager, category=category, key=key, name =assignment.__name__,))
            if portletHash not in hashlist:
                hashlist.append(portletHash)
            assignments.append({'category'    : category,
                                'key'         : key,
                                'name'        : assignment.__name__,
                                'assignment'  : assignment,
                                'hash'        : portletHash,
                                'stopUrls'    : ISolgemaPortletAssignment(assignment).stopUrls,
                                'manager'     : manager,
                                })

        managerUtility.listAllManagedPortlets = hashlist

        #order the portlets
        assignments.sort(lambda a,b:cmp(hashlist.index(a['hash']), hashlist.index(b['hash'])))

        li = []
        here_url = '/'.join(aq_inner(self.context).getPhysicalPath())
        for assigndict in assignments:
            stopped = False
            if assigndict.has_key('stopUrls') and hasattr(assigndict['stopUrls'], 'sort') and len(assigndict['stopUrls'])>0:
                for stopUrl in assigndict['stopUrls']:
                    if stopUrl in here_url:
                        stopped = True
            assigndict['stopped'] = stopped
            assigndict['here_url'] = here_url

        return assignments
예제 #24
0
 def testGlobalsNoGroups(self):
     ctx = IPortletContext(self.folder)
     g = ctx.globalPortletCategories()
     self.assertEquals(len(g), 3)
     self.assertEquals(g[0], ('content_type', 'Folder'))
     self.assertEquals(g[1], ('user', user_name))