def test_isLastItem(self): items = self.book.objectValues()[:] items.reverse() lastItem = items[0] adapter = INextPreviousProvider(self.book) self.assertEqual( lastItem, adapter.getLastItem(), 'Last item check failed.')
def test_getLastItem(self): items = self.book.objectValues()[:] items.reverse() lastItem = items[0] adapter = INextPreviousProvider(self.book) self.assertEqual( lastItem, adapter.getLastItem(), 'Incorrect last item')
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 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 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 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 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 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 getPreviousItem(self, obj, camefrom=None): """ return info about the previous item in the container """ if not self.order: return None order_reversed = list(reversed(self.order)) pos = order_reversed.index(obj.getId()) for oid in order_reversed[pos+1:]: data = self.getData(self.context[oid]) if data: return data # couldn't find one, let's see of our parent knows if self.isFirstItem(obj) and INavigationRoot.providedBy(self.context): return None else: parent = INextPreviousProvider(self.context.aq_parent) if parent and parent.enabled: return parent.getPreviousItem(self.context, camefrom) return None
def testPreviousItemOnlyShowViewable(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 previous = adapter.getPreviousItem(container.subDoc5) self.assertEqual(previous['id'], 'subDoc4') previous = adapter.getPreviousItem(container.subDoc4) self.assertEqual(previous['id'], 'subDoc2') previous = adapter.getPreviousItem(container.subDoc2) self.assertEqual(previous, 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): 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 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 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 testPreviousItemOnlyShowViewable(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 iid in range(1, 7): docid = container.invokeFactory("Document", "subDoc%d" % iid) doc = container[docid] if iid 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 previous = adapter.getPreviousItem(container.subDoc5) self.assertEqual(previous["id"], "subDoc4") previous = adapter.getPreviousItem(container.subDoc4) self.assertEqual(previous["id"], "subDoc2") previous = adapter.getPreviousItem(container.subDoc2) self.assertEqual(previous, None)
def testPreviousItemOnlyShowViewable(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 iid in range(1, 7): docid = container.invokeFactory('Document', 'subDoc%d' % iid) doc = container[docid] if iid 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 previous = adapter.getPreviousItem(container.subDoc5) self.assertEqual(previous['id'], 'subDoc4') previous = adapter.getPreviousItem(container.subDoc4) self.assertEqual(previous['id'], 'subDoc2') previous = adapter.getPreviousItem(container.subDoc2) self.assertEqual(previous, None)
def testPreviousItemOnlyShowViewable(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 previous = adapter.getPreviousItem(container.subDoc5) self.assertEqual(previous['id'], 'subDoc4') previous = adapter.getPreviousItem(container.subDoc4) self.assertEqual(previous['id'], 'subDoc2') previous = adapter.getPreviousItem(container.subDoc2) self.assertEqual(previous, 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)
def _provider(self): # Note - the next/previous provider is the container of this object! # This may not support next/previous navigation, so code defensively return INextPreviousProvider(aq_parent(aq_inner(self.context)), None)
def testIfFolderImplementsPreviousNext(self): self.assertTrue(INextPreviousProvider(self.portal.folder1, None))
def testNextPreviousEnablingOnCreation(self): self.assertTrue(INextPreviousProvider(self.portal.folder1).enabled)
def test_getFirstItem(self): firstItem = self.book.objectValues()[0] adapter = INextPreviousProvider(self.book) self.assertEqual( firstItem, adapter.getFirstItem(), 'Incorrect first item')
def test_stopAtFirst(self): firstItem = self.book.objectValues()[0] adapter = INextPreviousProvider(self.book) prevItem = adapter.getPreviousItem(firstItem) self.assertEqual(prevItem, None)
def testNextPreviousEnablingOnCreation(self): # This is tested properly in the doctest, the default z3c.form # value is not set here. self.failIf(INextPreviousProvider(self.portal.folder1).enabled)
def test_isFirstItem(self): firstItem = self.book.objectValues()[0] adapter = INextPreviousProvider(self.book) self.assertEqual( firstItem, adapter.getFirstItem(), 'First item check failed.')
def testIfFolderImplementsPreviousNext(self): self.failUnless(INextPreviousProvider(self.portal.folder1, None))
def testNextPreviousEnablingOnCreation(self): self.failUnless(INextPreviousProvider(self.portal.folder1).enabled)
def getNextPreviousParentValue(adapter_): context = adapter_.context nextprevious = INextPreviousProvider(context, None) if nextprevious is None: return False return nextprevious.enabled