Esempio n. 1
0
def get_paginated_objects(request, on_page=None, anchor=None):
    comments = Comment.objects.all().order_by('-date')
    paginator = SlidingPkPaginator(comments, on_page=10)

    return direct_to_template(request, "comments.html", {
        'comments' : paginator.get_objects(),
        'paginator' : paginator,
    })
class TestFormAction(UnitTestCase):
    def setUp(self):
        super(TestFormAction, self).setUp()
        self.paginator = SlidingPkPaginator([], anchor=1)

    def test_default_action_is_current_page(self):
        self.assert_equals(".", self.paginator.form_action)

    def test_paginator_with_reverse_lookup(self):
        self.paginator.view_name = "myapp-objects"
        self.assert_equals("/1/10/", unquote_plus(self.paginator.form_action))

    def test_post_parsing_anchor(self):
        self.paginator.parse_post({
                'anchor' : 1,
            }
        )
        self.assert_equals(1, self.paginator.anchor)
 def setUp(self):
     super(TestFormAction, self).setUp()
     self.paginator = SlidingPkPaginator([], anchor=1)
 def test_id_anchored_slicing(self):
     paginator = SlidingPkPaginator(Comment.objects.all().order_by('-pk'),
         anchor = self.comments[1].pk
     )
     self.assert_comments_equals(self.comments[1:11], paginator.get_objects())
 def test_custom_slicing(self):
     paginator = SlidingPkPaginator(Comment.objects.all().order_by('-pk'), on_page=20)
     self.assert_comments_equals(self.comments[0:20], paginator.get_objects())
 def test_default_slicing(self):
     paginator = SlidingPkPaginator(Comment.objects.all().order_by('-pk'))
     self.assert_comments_equals(self.comments[0:10], paginator.get_objects())