本文整理汇总了Python中djangae.contrib.pagination.Paginator类的典型用法代码示例。如果您正苦于以下问题:Python Paginator类的具体用法?Python Paginator怎么用?Python Paginator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Paginator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_empty_page
def test_empty_page(self):
paginator = Paginator(TestUser.objects.all().order_by("-first_name"), 1, allow_empty_first_page=False)
with self.assertRaises(django_paginator.EmptyPage):
self.assertEqual(paginator.page(5).object_list, [])
paginator = Paginator(TestUser.objects.all().order_by("-first_name"), 1)
self.assertEqual(paginator.page(5).object_list, [])
示例2: test_count_reads_ahead
def test_count_reads_ahead(self):
paginator = Paginator(TestUser.objects.all().order_by("first_name"), 1, readahead=2)
paginator.page(1)
self.assertEqual(3, paginator.count)
paginator.page(3)
self.assertEqual(4, paginator.count)
示例3: test_that_marker_is_read
def test_that_marker_is_read(self):
paginator = Paginator(TestUser.objects.all().order_by("first_name"), 1, readahead=1)
paginator.page(2)
with sleuth.watch("djangae.contrib.pagination.paginator._get_marker") as get_marker:
paginator.page(4)
self.assertTrue(get_marker.called)
self.assertIsNotNone(get_marker.call_returns[0][0])
self.assertEqual(1, get_marker.call_returns[0][1])
示例4: test_that_readahead_stores_markers
def test_that_readahead_stores_markers(self):
paginator = Paginator(TestUser.objects.all().order_by("first_name"), 1, readahead=4)
expected_markers = [ None ] + list(TestUser.objects.all().order_by("first_name").values_list(paginator.field_required, flat=True))[:3]
paginator.page(1)
query_id = queryset_identifier(paginator.object_list)
actual_markers = []
for i in xrange(1, 5):
actual_markers.append(_get_marker(query_id, i)[0])
self.assertEqual(expected_markers, actual_markers)
# Now change the per page number
paginator = Paginator(TestUser.objects.all().order_by("first_name"), 2, readahead=4)
all_markers = list(TestUser.objects.all().order_by("first_name").values_list(paginator.field_required, flat=True))
expected_markers = [ None, all_markers[1] ]
paginator.page(1)
query_id = queryset_identifier(paginator.object_list)
actual_markers = []
for i in xrange(1, 3):
actual_markers.append(_get_marker(query_id, i)[0])
self.assertEqual(expected_markers, actual_markers)
示例5: test_ordering
def test_ordering(self):
paginator = Paginator(TestUser.objects.all().order_by("created"), 1, readahead=2)
paginator.page(1)
self.assertEqual([self.u1, self.u2, self.u3, self.u4], list(paginator.object_list))
paginator = Paginator(TestUser.objects.all().order_by("-created"), 1, readahead=2)
paginator.page(1)
self.assertEqual([self.u4, self.u3, self.u2, self.u1], list(paginator.object_list))
示例6: test_page_jump_updates_count_correctly
def test_page_jump_updates_count_correctly(self):
paginator = Paginator(TestUser.objects.all().order_by("first_name"), 1, readahead=1)
paginator.page(1)
self.assertEqual(2, paginator.count)
paginator.page(3)
self.assertEqual(4, paginator.count)
示例7: test_pages_correct
def test_pages_correct(self):
paginator = Paginator(TestUser.objects.all().order_by("first_name"), 1) # 1 item per page
self.assertEqual("A", paginator.page(1).object_list[0].first_name)
self.assertEqual("A", paginator.page(2).object_list[0].first_name)
self.assertEqual("B", paginator.page(3).object_list[0].first_name)
self.assertEqual("B", paginator.page(4).object_list[0].first_name)
paginator = Paginator(TestUser.objects.all().order_by("first_name", "last_name"), 1) # 1 item per page
self.assertEqual(self.u1, paginator.page(1).object_list[0])
self.assertEqual(self.u2, paginator.page(2).object_list[0])
self.assertEqual(self.u3, paginator.page(3).object_list[0])
self.assertEqual(self.u4, paginator.page(4).object_list[0])
paginator = Paginator(TestUser.objects.all().order_by("first_name", "-last_name"), 1) # 1 item per page
self.assertEqual(self.u2, paginator.page(1).object_list[0])
self.assertEqual(self.u1, paginator.page(2).object_list[0])
self.assertEqual(self.u4, paginator.page(3).object_list[0])
self.assertEqual(self.u3, paginator.page(4).object_list[0])
paginator = Paginator(TestUser.objects.all().order_by("-first_name"), 1) # 1 item per page
self.assertEqual(self.u4, paginator.page(1).object_list[0])
self.assertEqual(self.u3, paginator.page(2).object_list[0])
self.assertEqual(self.u2, paginator.page(3).object_list[0])
self.assertEqual(self.u1, paginator.page(4).object_list[0])
with self.assertRaises(PaginationOrderingRequired):
paginator = Paginator(TestUser.objects.all().order_by("-first_name", "last_name"), 1) # 1 item per page
list(paginator.page(1).object_list)
# test paging when last page has less than per_page objects
paginator = Paginator(TestUser.objects.all().order_by("first_name"), 3) # 3 items per page
self.assertEqual(
sorted([self.u1.pk, self.u2.pk, self.u3.pk]),
sorted([x.pk for x in paginator.page(1).object_list])
)
self.assertEqual(
sorted([self.u4.pk]),
sorted([x.pk for x in paginator.page(2).object_list])
)
示例8: test_default_ordering
def test_default_ordering(self):
""" Tests that pagination works using just the model's default ordering. """
paginator = Paginator(TestUser.objects.all(), 1, readahead=2)
paginator.page(1)
self.assertEqual([self.u1, self.u2, self.u3, self.u4], list(paginator.object_list))