def test_pagination_page_range(self): """ Regression tests for ticket #15653: ensure the number of pages generated for changelist views are correct. """ # instantiating and setting up ChangeList object m = GroupAdmin(Group, custom_site) request = self.factory.get('/group/') cl = ChangeList(request, Group, *get_changelist_args(m)) per_page = cl.list_per_page = 10 for page_num, objects_count, expected_page_range in [ (0, per_page, []), (0, per_page * 2, list(range(2))), (5, per_page * 11, list(range(11))), (5, per_page * 12, [0, 1, 2, 3, 4, 5, 6, 7, 8, '.', 10, 11]), (6, per_page * 12, [0, 1, '.', 3, 4, 5, 6, 7, 8, 9, 10, 11]), (6, per_page * 13, [0, 1, '.', 3, 4, 5, 6, 7, 8, 9, '.', 11, 12]), ]: # assuming we have exactly `objects_count` objects Group.objects.all().delete() for i in range(objects_count): Group.objects.create(name='test band') # setting page number and calculating page range cl.page_num = page_num cl.get_results(request) real_page_range = pagination(cl)['page_range'] self.assertListEqual( expected_page_range, list(real_page_range), )
def get_pagination_links(self): links = list() changelist = self.get_changelist() paginator, page_num = changelist.paginator, changelist.page_num from django.contrib.admin.templatetags.admin_list import pagination from django.contrib.admin.views.main import PAGE_VAR ctx = pagination(changelist) classes = ["pagination"] for page in ctx["page_range"]: if page == '.': continue url = changelist.get_query_string({PAGE_VAR: page}) links.append(Link(url=url, prompt=u"page %s" % page, classes=classes, rel="pagination")) if ctx["show_all_url"]: links.append(Link(url=ctx["show_all_url"], prompt="show all", classes=classes, rel="pagination")) return links
def test_pagination_page_range(self): """ Regression tests for ticket #15653: ensure the number of pages generated for changelist views are correct. """ # instantiating and setting up ChangeList object m = GroupAdmin(Group, custom_site) request = self.factory.get("/group/") cl = ChangeList( request, Group, m.list_display, m.list_display_links, m.list_filter, m.date_hierarchy, m.search_fields, m.list_select_related, m.list_per_page, m.list_max_show_all, m.list_editable, m, ) per_page = cl.list_per_page = 10 for page_num, objects_count, expected_page_range in [ (0, per_page, []), (0, per_page * 2, list(range(2))), (5, per_page * 11, list(range(11))), (5, per_page * 12, [0, 1, 2, 3, 4, 5, 6, 7, 8, ".", 10, 11]), (6, per_page * 12, [0, 1, ".", 3, 4, 5, 6, 7, 8, 9, 10, 11]), (6, per_page * 13, [0, 1, ".", 3, 4, 5, 6, 7, 8, 9, ".", 11, 12]), ]: # assuming we have exactly `objects_count` objects Group.objects.all().delete() for i in range(objects_count): Group.objects.create(name="test band") # setting page number and calculating page range cl.page_num = page_num cl.get_results(request) real_page_range = pagination(cl)["page_range"] self.assertListEqual(expected_page_range, list(real_page_range))
def test_pagination_page_range(self): """ Regression tests for ticket #15653: ensure the number of pages generated for changelist views are correct. """ # instantiating and setting up ChangeList object m = GroupAdmin(Group, admin.site) request = self.factory.get('/group/') cl = ChangeList(request, Group, m.list_display, m.list_display_links, m.list_filter, m.date_hierarchy, m.search_fields, m.list_select_related, m.list_per_page, m.list_max_show_all, m.list_editable, m) per_page = cl.list_per_page = 10 for page_num, objects_count, expected_page_range in [ (0, per_page, []), (0, per_page * 2, range(2)), (5, per_page * 11, list(range(11))), (5, per_page * 12, [0, 1, 2, 3, 4, 5, 6, 7, 8, '.', 10, 11]), (6, per_page * 12, [0, 1, '.', 3, 4, 5, 6, 7, 8, 9, 10, 11]), (6, per_page * 13, [0, 1, '.', 3, 4, 5, 6, 7, 8, 9, '.', 11, 12]), ]: # assuming we have exactly `objects_count` objects Group.objects.all().delete() for i in range(objects_count): Group.objects.create(name='test band') # setting page number and calculating page range cl.page_num = page_num cl.get_results(request) real_page_range = pagination(cl)['page_range'] self.assertEqual( expected_page_range, real_page_range, )
def pagination_top(cl): return pagination(cl)
def ipagination(context, cl): tpl = select_template(cl.model_admin.get_template(context["request"], cl.model_admin.pagination_template)) ctx = al.pagination(cl) return tpl.render(Context(ctx))
def result_pagination(cl): return pagination(cl)
def tabular_inline_pagination(cl): return pagination(cl)
def dt_pagination(cl): return pagination(cl)