Пример #1
0
    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 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)
Пример #3
0
 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 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)
Пример #5
0
    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 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)
Пример #7
0
    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)
Пример #8
0
 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
Пример #9
0
 def test_stopAtFirst(self):
     firstItem = self.book.objectValues()[0]
     adapter = INextPreviousProvider(self.book)
     prevItem = adapter.getPreviousItem(firstItem)
     self.assertEqual(prevItem, None)