示例#1
0
 def testUseMacro(self):
     r = self.renderer(assignment=classic.Assignment(
         template='portlet_recent', macro='portlet'))
     self.assertEqual(True, r.use_macro())
     r = self.renderer(assignment=classic.Assignment(
         template='portlet_recent', macro=None))
     self.assertEqual(False, r.use_macro())
示例#2
0
 def testPathExpression(self):
     r = self.renderer(assignment=classic.Assignment(
         template='portlet_recent', macro='portlet'))
     self.assertEqual('context/portlet_recent/macros/portlet',
                      r.path_expression())
     r = self.renderer(assignment=classic.Assignment(
         template='portlet_recent', macro=None))
     self.assertEqual('context/portlet_recent', r.path_expression())
示例#3
0
 def testNameChooser(self):
     mapping = PortletAssignmentMapping()
     chooser = INameChooser(mapping)
     c = classic.Assignment()
     mapping[chooser.chooseName(None, c)] = c
     self.failUnless(c.__name__)
     d = classic.Assignment()
     self.failIfEqual(chooser.chooseName(None, d), c.__name__)
示例#4
0
 def testNameChooser(self):
     mapping = PortletAssignmentMapping()
     chooser = INameChooser(mapping)
     c = classic.Assignment()
     mapping[chooser.chooseName(None, c)] = c
     self.assertTrue(c.__name__)
     d = classic.Assignment()
     self.assertFalse(chooser.chooseName(None, d) == c.__name__)
示例#5
0
    def testInvokeEditView(self):
        mapping = PortletAssignmentMapping()
        request = self.folder.REQUEST

        mapping['foo'] = classic.Assignment(template='portlet_recent', macro='portlet')
        editview = getMultiAdapter((mapping['foo'], request), name='edit')
        self.failUnless(isinstance(editview, classic.EditForm))
示例#6
0
 def testGetPortletFromContext(self):
     mapping = getMultiAdapter((self.portal, self.manager), IPortletAssignmentMapping)
     c = classic.Assignment()
     mapping['foo'] = c
     path = '/'.join(self.portal.getPhysicalPath())
     a = assignment_from_key(self.portal, u'plone.leftcolumn', CONTEXT_CATEGORY, path, 'foo')
     self.assertEqual(c, a)
示例#7
0
    def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
        context = context or self.folder
        request = request or self.folder.REQUEST
        view = view or self.folder.restrictedTraverse('@@plone')
        manager = manager or getUtility(IPortletManager, name='plone.leftcolumn', context=self.portal)
        assignment = assignment or classic.Assignment(template='portlet_recent', macro='portlet')

        return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
示例#8
0
 def testContentTypeNamespace(self):
     assignment = classic.Assignment()
     manager = getUtility(IPortletManager, name='plone.leftcolumn')
     mapping = self.portal.restrictedTraverse('++contenttypeportlets++plone.leftcolumn+Image')
     self._assertSameObject(aq_parent(mapping), self.portal)
     mapping['foo'] = assignment
     self._assertSameObject(manager[CONTENT_TYPE_CATEGORY]['Image']['foo'], assignment)
     self.assertEqual('++contenttypeportlets++plone.leftcolumn+Image', mapping.id)
示例#9
0
 def testGroupNamespace(self):
     assignment = classic.Assignment()
     manager = getUtility(IPortletManager, name='plone.leftcolumn')
     mapping = self.portal.restrictedTraverse('++groupportlets++plone.leftcolumn+Reviewers')
     self._assertSameObject(aq_parent(mapping), self.portal)
     mapping['foo'] = assignment
     self._assertSameObject(manager[GROUP_CATEGORY]['Reviewers']['foo'], assignment)
     self.assertEqual('++groupportlets++plone.leftcolumn+Reviewers', mapping.id)
示例#10
0
 def testDashboardNamespace(self):
     assignment = classic.Assignment()
     manager = getUtility(IPortletManager, name='plone.dashboard1')
     mapping = self.portal.restrictedTraverse('++dashboard++plone.dashboard1+' + user_name)
     self._assertSameObject(aq_parent(mapping), self.portal)
     mapping['foo'] = assignment
     self._assertSameObject(manager[USER_CATEGORY][user_name]['foo'], assignment)
     self.assertEqual('++dashboard++plone.dashboard1+' + user_name, mapping.id)
示例#11
0
    def testRenderer(self):
        context = self.folder
        request = self.folder.REQUEST
        view = self.folder.restrictedTraverse('@@plone')
        manager = getUtility(IPortletManager, name='plone.leftcolumn', context=self.portal)
        assignment = classic.Assignment(template='portlet_recent', macro='portlet')

        renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
        self.failUnless(isinstance(renderer, classic.Renderer))
示例#12
0
 def testContextNamespace(self):
     assignment = classic.Assignment()
     manager = getUtility(IPortletManager, name='plone.leftcolumn')
     mapping = self.folder.restrictedTraverse('++contextportlets++plone.leftcolumn')
     target = getMultiAdapter((self.folder, manager), IPortletAssignmentMapping)
     self._assertSameObject(aq_parent(mapping), self.folder)
     mapping['foo'] = assignment
     self._assertSameObject(target['foo'], assignment)
     self.assertEqual('++contextportlets++plone.leftcolumn', mapping.id)
示例#13
0
    def testEquivalence(self):
        mapping = getMultiAdapter((self.folder, self.manager),
                                  IPortletAssignmentMapping)
        c = classic.Assignment()
        mapping['foo'] = c

        mapping2 = getMultiAdapter((self.folder, self.manager),
                                   IPortletAssignmentMapping)
        self.assertEquals(mapping2['foo'], c)
示例#14
0
 def testGetPortletFromContextUnicodePath(self):
     """Do not fail, if path is a unicode object.
     plone.portlets.utils.unhashPortletInfo returns a unicode path key.
     """
     mapping = getMultiAdapter((self.portal, self.manager), IPortletAssignmentMapping)
     c = classic.Assignment()
     mapping['foo'] = c
     path = u'/'.join(self.portal.getPhysicalPath())
     a = assignment_from_key(self.portal, u'plone.leftcolumn', CONTEXT_CATEGORY, path, 'foo')
     self.assertEqual(c, a)
示例#15
0
    def initializeArchetype(self, **kwargs):
        ATBTreeFolder.initializeArchetype(self, **kwargs)

        left = getUtility(IPortletManager, name='plone.leftcolumn')
        right = getUtility(IPortletManager, name='plone.rightcolumn')
        
        leftAssignable = getMultiAdapter((self, left), IPortletAssignmentMapping).__of__(self)
        rightAssignable = getMultiAdapter((self, right), IPortletAssignmentMapping).__of__(self)
        
#        IPortletPermissionChecker(leftAssignable)()
#        IPortletPermissionChecker(rightAssignable)()
        
        leftChooser = INameChooser(leftAssignable)
        rightChooser = INameChooser(rightAssignable)
        

        # Set slot properties
        left_slots = zconf.coreblog2.left_slots_default
        for item in left_slots:
            path = item.split('/')
            if len(path) == 4:
                newPortlet = classic.Assignment(path[1], path[3])
                leftAssignable[leftChooser.chooseName(None, newPortlet)] = newPortlet

        right_slots = zconf.coreblog2.right_slots_default
        for item in right_slots:
            path = item.split('/')
            if len(path) == 4:
                newPortlet = classic.Assignment(path[1], path[3])
                rightAssignable[rightChooser.chooseName(None, newPortlet)] = newPortlet
        
        labLeftColumnManager = getMultiAdapter((self, left), ILocalPortletAssignmentManager)
        labLeftColumnManager.setBlacklistStatus(CONTEXT_CATEGORY, True)
        labRightColumnManager = getMultiAdapter((self, right), ILocalPortletAssignmentManager)
        labRightColumnManager.setBlacklistStatus(CONTEXT_CATEGORY, True) 
        
        # finalize
        # make subfolders, etc.
        self.cbfinalize_creation(self,
                                (comment_folder_id, catetory_folder_id, 
                                 stuff_folder_id, images_folder_id))
        self.indexObject()
示例#16
0
    def testGroupDashboardNamespaceChecker(self):
        assignment = classic.Assignment()
        manager = getUtility(IPortletManager, name='plone.dashboard1')
        mapping = self.portal.restrictedTraverse('++groupdashboard++plone.dashboard1+Reviewers')

        checker = IPortletPermissionChecker(mapping)

        self.setRoles(('Manager', ))
        checker() # no exception

        self.setRoles(('Member', ))
        self.assertRaises(Unauthorized, checker)
示例#17
0
def createClassicPortletWithCountryDropdown(self):
    """ """
    parent = getParent(self)
    obj = getattr(parent, 'oshnetwork')
    column = getUtility(IPortletManager, name='plone.leftcolumn')
    manager = getMultiAdapter((
        obj,
        column,
    ), IPortletAssignmentMapping)
    assignment = classic.Assignment(template='oshnetwork_country_select',
                                    macro='portlet')
    chooser = INameChooser(manager)
    manager[chooser.chooseName(None, assignment)] = assignment
示例#18
0
def addExternalPortlet(self):
    """ """
    parent = getParent(self)
    obj = getattr(parent, 'oshnetwork')
    column = getUtility(IPortletManager, name='plone.rightcolumn')
    manager = getMultiAdapter((
        obj,
        column,
    ), IPortletAssignmentMapping)
    assignment = classic.Assignment(
        template='oshnetwork_external_links_portlet', macro='portlet')
    chooser = INameChooser(manager)
    manager[chooser.chooseName(None, assignment)] = assignment
示例#19
0
def convert_legacy_portlets(context):
    """Convert legacy portlets (left_slots, right_slots) in the given
    context to new-style portlets.
    """

    portletsMapping = {
        'portlet_login': login.Assignment(),
        'portlet_news': news.Assignment(count=5),
        'portlet_navigation': navigation.Assignment(),
        'portlet_review': review.Assignment(),
        'portlet_recent': recent.Assignment(count=5),
        'portlet_related': DONT_MIGRATE,
        'portlet_languages': DONT_MIGRATE,
        'portlet_calendar': DONT_MIGRATE,
        'portlet_events': DONT_MIGRATE,
    }

    if HAS_PLONE_APP_EVENT:
        portletsMapping.update({
            'portlet_calendar': calendar.Assignment(),
            'portlet_events': events.Assignment(count=5),
        })

    # Convert left_slots and right_slots to portlets

    left = getUtility(IPortletManager, name='plone.leftcolumn')
    right = getUtility(IPortletManager, name='plone.rightcolumn')

    leftAssignable = getMultiAdapter((context, left),
                                     IPortletAssignmentMapping).__of__(context)
    rightAssignable = getMultiAdapter(
        (context, right), IPortletAssignmentMapping).__of__(context)

    IPortletPermissionChecker(leftAssignable)()
    IPortletPermissionChecker(rightAssignable)()

    leftChooser = INameChooser(leftAssignable)
    rightChooser = INameChooser(rightAssignable)

    left_slots = getattr(aq_base(context), 'left_slots', [])
    right_slots = getattr(aq_base(context), 'right_slots', [])

    for item in left_slots:
        path = item.split('/')
        if len(path) == 4:
            newPortlet = portletsMapping.get(path[1], None)
            if newPortlet is None and path[0] in (
                    'context', 'here') and path[2] == 'macros':
                newPortlet = classic.Assignment(path[1], path[3])
            if newPortlet is not None and newPortlet is not DONT_MIGRATE:
                leftAssignable[leftChooser.chooseName(None,
                                                      newPortlet)] = newPortlet

    for item in right_slots:
        path = item.split('/')
        if len(path) == 4:
            newPortlet = portletsMapping.get(path[1], None)
            if newPortlet is None and path[0] in (
                    'context', 'here') and path[2] == 'macros':
                newPortlet = classic.Assignment(path[1], path[3])
            if newPortlet is not None and newPortlet is not DONT_MIGRATE:
                rightAssignable[rightChooser.chooseName(
                    None, newPortlet)] = newPortlet

    context.left_slots = []
    context.right_slots = []
示例#20
0
 def testGetPortletFromUserCategory(self):
     c = classic.Assignment()
     self.cat[user_name]['foo'] = c
     a = assignment_from_key(self.portal, u'plone.leftcolumn', USER_CATEGORY, user_name, 'foo')
     self.assertEqual(c, a)
示例#21
0
 def testInterfaces(self):
     portlet = classic.Assignment(template='portlet_recent',
                                  macro='portlet')
     self.assertTrue(IPortletAssignment.providedBy(portlet))
     self.assertTrue(IPortletDataProvider.providedBy(portlet.data))
示例#22
0
 def testRenderClassicPortlet(self):
     r = self.renderer(assignment=classic.Assignment(template='@@view',
                                                     macro='content-core'))
     r.render()
示例#23
0
 def afterSetUp(self):
     self.mapping = PortletAssignmentMapping()
     c = classic.Assignment()
     self.mapping['foo'] = c
     self.traverser = getMultiAdapter((self.mapping, self.folder.REQUEST),
                                      IBrowserPublisher)