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())
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())
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__)
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__)
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))
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)
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)
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)
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)
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)
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))
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)
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)
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)
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()
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)
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
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
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 = []
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)
def testInterfaces(self): portlet = classic.Assignment(template='portlet_recent', macro='portlet') self.assertTrue(IPortletAssignment.providedBy(portlet)) self.assertTrue(IPortletDataProvider.providedBy(portlet.data))
def testRenderClassicPortlet(self): r = self.renderer(assignment=classic.Assignment(template='@@view', macro='content-core')) r.render()
def afterSetUp(self): self.mapping = PortletAssignmentMapping() c = classic.Assignment() self.mapping['foo'] = c self.traverser = getMultiAdapter((self.mapping, self.folder.REQUEST), IBrowserPublisher)