当前位置: 首页>>代码示例>>Python>>正文


Python Paginator.page方法代码示例

本文整理汇总了Python中djangae.contrib.pagination.Paginator.page方法的典型用法代码示例。如果您正苦于以下问题:Python Paginator.page方法的具体用法?Python Paginator.page怎么用?Python Paginator.page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在djangae.contrib.pagination.Paginator的用法示例。


在下文中一共展示了Paginator.page方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_empty_page

# 需要导入模块: from djangae.contrib.pagination import Paginator [as 别名]
# 或者: from djangae.contrib.pagination.Paginator import page [as 别名]
    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, [])
开发者ID:VincentStephens,项目名称:djangae,代码行数:9,代码来源:tests.py

示例2: test_that_readahead_stores_markers

# 需要导入模块: from djangae.contrib.pagination import Paginator [as 别名]
# 或者: from djangae.contrib.pagination.Paginator import page [as 别名]
    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)
开发者ID:VincentStephens,项目名称:djangae,代码行数:32,代码来源:tests.py

示例3: test_count_reads_ahead

# 需要导入模块: from djangae.contrib.pagination import Paginator [as 别名]
# 或者: from djangae.contrib.pagination.Paginator import page [as 别名]
    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)
开发者ID:VincentStephens,项目名称:djangae,代码行数:10,代码来源:tests.py

示例4: test_ordering

# 需要导入模块: from djangae.contrib.pagination import Paginator [as 别名]
# 或者: from djangae.contrib.pagination.Paginator import page [as 别名]
    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))
开发者ID:VincentStephens,项目名称:djangae,代码行数:10,代码来源:tests.py

示例5: test_that_marker_is_read

# 需要导入模块: from djangae.contrib.pagination import Paginator [as 别名]
# 或者: from djangae.contrib.pagination.Paginator import page [as 别名]
    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])
开发者ID:VincentStephens,项目名称:djangae,代码行数:12,代码来源:tests.py

示例6: test_page_jump_updates_count_correctly

# 需要导入模块: from djangae.contrib.pagination import Paginator [as 别名]
# 或者: from djangae.contrib.pagination.Paginator import page [as 别名]
 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)
开发者ID:VincentStephens,项目名称:djangae,代码行数:8,代码来源:tests.py

示例7: test_pages_correct

# 需要导入模块: from djangae.contrib.pagination import Paginator [as 别名]
# 或者: from djangae.contrib.pagination.Paginator import page [as 别名]
    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])
        )
开发者ID:VincentStephens,项目名称:djangae,代码行数:42,代码来源:tests.py

示例8: test_default_ordering

# 需要导入模块: from djangae.contrib.pagination import Paginator [as 别名]
# 或者: from djangae.contrib.pagination.Paginator import page [as 别名]
 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))
开发者ID:andreipetre,项目名称:djangae,代码行数:7,代码来源:tests.py


注:本文中的djangae.contrib.pagination.Paginator.page方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。