def testNextPreviousItems(self): container = self.portal[self.portal.invokeFactory(self._portal_type, 'case3')] for id in range(1, 4): container.invokeFactory('Document', 'subDoc%d' % id) from OFS.Folder import manage_addFolder manage_addFolder(container, 'notacontentishtype') for id in range(5, 6): container.invokeFactory('Document', 'subDoc%d' % id) adapter = INextPreviousProvider(container) # text data for next/previous items next = adapter.getNextItem(container.subDoc2) self.assertEqual(next['id'], 'subDoc3') self.assertEqual(next['portal_type'], 'Document') self.assertEqual(next['url'], container.subDoc3.absolute_url()) previous = adapter.getPreviousItem(container.subDoc2) self.assertEqual(previous['id'], 'subDoc1') self.assertEqual(previous['portal_type'], 'Document') self.assertEqual(previous['url'], container.subDoc1.absolute_url()) # #11234 not contentish contents shouldn't be returned # as next or previous content next = adapter.getNextItem(container.subDoc3) self.assertEqual(next['id'], 'subDoc5') previous = adapter.getPreviousItem(container.subDoc5) self.assertEqual(previous['id'], 'subDoc3') # first item should not have a previous item previous = adapter.getPreviousItem(container.subDoc1) self.assertEqual(previous, None) # last item should not have a next item next = adapter.getNextItem(container.subDoc5) self.assertEqual(next, None)
def testNextPreviousItems(self): container = self.folder[self.folder.invokeFactory('Folder', 'case3')] for id in range(1, 4): container.invokeFactory('Document', 'subDoc%d' % id) from OFS.Folder import manage_addFolder manage_addFolder(container, 'notacontentishtype') for id in range(5, 6): container.invokeFactory('Document', 'subDoc%d' % id) adapter = INextPreviousProvider(container) # text data for next/previous items next = adapter.getNextItem(container.subDoc2) self.assertEqual(next['id'], 'subDoc3') self.assertEqual(next['portal_type'], 'Document') self.assertEqual(next['url'], container.subDoc3.absolute_url()) previous = adapter.getPreviousItem(container.subDoc2) self.assertEqual(previous['id'], 'subDoc1') self.assertEqual(previous['portal_type'], 'Document') self.assertEqual(previous['url'], container.subDoc1.absolute_url()) # #11234 not contentish contents shouldn't be returned # as next or previous content next = adapter.getNextItem(container.subDoc3) self.assertEqual(next['id'], 'subDoc5') previous = adapter.getPreviousItem(container.subDoc5) self.assertEqual(previous['id'], 'subDoc3') # first item should not have a previous item previous = adapter.getPreviousItem(container.subDoc1) self.assertEqual(previous, None) # last item should not have a next item next = adapter.getNextItem(container.subDoc5) self.assertEqual(next, None)
def testNextPreviousItems(self): self.folder.invokeFactory('Folder', 'case3') for documentCounter in range(1, 6): self.folder.case3.invokeFactory('Document', 'subDoc%d' % documentCounter) container = self.folder.case3 testedItem = container.subDoc2 #set up the adapter for the folder adapter = INextPreviousProvider(container) #test the next item of subDoc2 next = adapter.getNextItem(self.folder.case3.subDoc2) self.failUnlessEqual(next["id"], 'subDoc3') #test that the contenttype is defined correct self.failUnlessEqual(next["portal_type"], 'Document') #test the previous item of subDoc2 previous = adapter.getPreviousItem(self.folder.case3.subDoc2) self.failUnlessEqual(previous["id"], 'subDoc1') #first item should not have a previous item previous = adapter.getPreviousItem(self.folder.case3.subDoc1) self.failUnlessEqual(previous, None) #last item should not have a next item next = adapter.getNextItem(self.folder.case3.subDoc5) self.failUnlessEqual(next, None)
def test_getNextItem(self): adapter = INextPreviousProvider(self.book) items = self.book.objectValues() currentItem = items[0] nextItem = adapter.getNextItem(currentItem) self.assertEqual(nextItem['url'], items[1].absolute_url()) currentItem = items[1] nextItem = adapter.getNextItem(currentItem) self.assertEqual(nextItem['url'], items[2].absolute_url())
def test_nextItemExcludedFromNav(self): """ If 'excludedFromNav' is set, the adapter should ignore this item. """ firstItem = self.book.objectValues()[0] secondItem = self.book.objectValues()[1] adapter = INextPreviousProvider(self.book) secondItem.setExcludeFromNav(True) item_data = adapter.getNextItem(firstItem) assert secondItem.absolute_url() != item_data['url'] self.assertEqual(item_data['url'], self.book.objectValues()[2].absolute_url()) secondItem.setExcludeFromNav(False) item_data = adapter.getNextItem(firstItem) assert secondItem.absolute_url() == item_data['url'] self.assertEqual(item_data['url'], self.book.objectValues()[1].absolute_url())
def update(self): self.next = None self.previous = None provider = INextPreviousProvider(aq_parent(self.context), None) if provider is not None: self.next = provider.getNextItem(self.context) self.previous = provider.getPreviousItem(self.context) super(DocumentActions, self).update()
def testNextItemOnlyShowViewable(self): container = self.portal[self.portal.invokeFactory(self._portal_type, 'case3')] # create objects [subDoc1,subDoc2,subDoc3,subDoc4,subDoc5,subDoc6] # published objects [subDoc2, subDoc4, subDoc5] setRoles(self.portal, TEST_USER_ID, ['Manager']) for id in range(1, 7): doc = container[container.invokeFactory('Document', 'subDoc%d' % id)] if id in [2,4,5]: self.wf.doActionFor(doc, "publish") # Member should only see the published items logout() login(self.portal, 'user_std') adapter = INextPreviousProvider(container) # text data for next/tems next = adapter.getNextItem(container.subDoc2) self.assertEqual(next['id'], 'subDoc4') next = adapter.getNextItem(container.subDoc4) self.assertEqual(next['id'], 'subDoc5') next = adapter.getNextItem(container.subDoc5) self.assertEqual(next, None)
def testNextItemOnlyShowViewable(self): container = self.folder[self.folder.invokeFactory("Folder", "case3")] # create objects [subDoc1,subDoc2,subDoc3,subDoc4,subDoc5,subDoc6] # published objects [subDoc2, subDoc4, subDoc5] self.setRoles(("Manager",)) for id in range(1, 7): docid = container.invokeFactory("Document", "subDoc%d" % id) doc = container[docid] if id in [2, 4, 5]: self.wf.doActionFor(doc, "publish") # Member should only see the published items self.logout() self.login("user_std") adapter = INextPreviousProvider(container) # text data for next/tems next = adapter.getNextItem(container.subDoc2) self.assertEqual(next["id"], "subDoc4") next = adapter.getNextItem(container.subDoc4) self.assertEqual(next["id"], "subDoc5") next = adapter.getNextItem(container.subDoc5) self.assertEqual(next, None)
def testNextItemOnlyShowViewable(self): container = self.folder[self.folder.invokeFactory('Folder', 'case3')] # create objects [subDoc1,subDoc2,subDoc3,subDoc4,subDoc5,subDoc6] # published objects [subDoc2, subDoc4, subDoc5] self.setRoles(("Manager", )) for id in range(1, 7): docid = container.invokeFactory('Document', 'subDoc%d' % id) doc = container[docid] if id in [2, 4, 5]: self.wf.doActionFor(doc, "publish") # Member should only see the published items self.logout() self.login('user_std') adapter = INextPreviousProvider(container) # text data for next/tems next = adapter.getNextItem(container.subDoc2) self.assertEqual(next['id'], 'subDoc4') next = adapter.getNextItem(container.subDoc4) self.assertEqual(next['id'], 'subDoc5') next = adapter.getNextItem(container.subDoc5) self.assertEqual(next, None)
def testNextItemOnlyShowViewable(self): container = self.portal[self.portal.invokeFactory( self._portal_type, 'case3')] # create objects [subDoc1,subDoc2,subDoc3,subDoc4,subDoc5,subDoc6] # published objects [subDoc2, subDoc4, subDoc5] setRoles(self.portal, TEST_USER_ID, ['Manager']) for id in range(1, 7): doc = container[container.invokeFactory('Document', 'subDoc{0}'.format(id))] if id in [2, 4, 5]: self.wf.doActionFor(doc, 'publish') # Member should only see the published items logout() login(self.portal, 'user_std') adapter = INextPreviousProvider(container) # text data for next/tems next = adapter.getNextItem(container.subDoc2) self.assertEqual(next['id'], 'subDoc4') next = adapter.getNextItem(container.subDoc4) self.assertEqual(next['id'], 'subDoc5') next = adapter.getNextItem(container.subDoc5) self.assertEqual(next, None)
def getNextItem(self, obj, camefrom=None): """ return info about the next item in the container """ if not self.order: return None pos = self.context.getObjectPosition(obj.getId()) for oid in self.order[pos+1:]: data = self.getData(self.context[oid]) if data: return data # couldn't find one, let's see of our parent knows parent = INextPreviousProvider(self.context.aq_parent) if parent and parent.enabled: return parent.getNextItem(self.context, camefrom) return None
def testNextPreviousItems(self): manual = self.hc.manual_folder.manual section1 = manual.section1 section2 = manual.section2 #section3 = manual.section3 # set up the adapter for the sec2 adapter = INextPreviousProvider(section2) # forwards from 2.2. next = adapter.getNextItem(section2.page2) self.failUnlessEqual(next["title"], '2.3. ') # backwards previous = adapter.getPreviousItem(section2.page2) self.failUnlessEqual(previous["title"], '2.1. ') # backwards from 2.1. previous = adapter.getPreviousItem(section2.page1) self.failUnlessEqual(previous["title"], '2. ') # forwards from 2.3., ignoring the image and the file next = adapter.getNextItem(section2.page3) self.failUnlessEqual(next["title"], '3. ') adapter = INextPreviousProvider(manual) # forwards from 2. next = adapter.getNextItem(section2) self.failUnlessEqual(next["title"], '2.1. ') # backwards previous = adapter.getPreviousItem(section2) self.failUnlessEqual(previous["title"], '1.3. ') # 1. has no previous item previous = adapter.getPreviousItem(section1) self.failUnlessEqual(previous, None)
def testNextPreviousItems(self): container = self.folder[self.folder.invokeFactory("Folder", "case3")] for id in range(1, 4): container.invokeFactory("Document", "subDoc%d" % id) from OFS.Folder import manage_addFolder manage_addFolder(container, "notacontentishtype") for id in range(5, 6): container.invokeFactory("Document", "subDoc%d" % id) adapter = INextPreviousProvider(container) # text data for next/previous items next = adapter.getNextItem(container.subDoc2) self.assertEqual(next["id"], "subDoc3") self.assertEqual(next["portal_type"], "Document") self.assertEqual(next["url"], container.subDoc3.absolute_url()) previous = adapter.getPreviousItem(container.subDoc2) self.assertEqual(previous["id"], "subDoc1") self.assertEqual(previous["portal_type"], "Document") self.assertEqual(previous["url"], container.subDoc1.absolute_url()) # #11234 not contentish contents shouldn't be returned # as next or previous content next = adapter.getNextItem(container.subDoc3) self.assertEqual(next["id"], "subDoc5") previous = adapter.getPreviousItem(container.subDoc5) self.assertEqual(previous["id"], "subDoc3") # first item should not have a previous item previous = adapter.getPreviousItem(container.subDoc1) self.assertEqual(previous, None) # last item should not have a next item next = adapter.getNextItem(container.subDoc5) self.assertEqual(next, None)