|
4 | 4 |
|
5 | 5 | import json |
6 | 6 |
|
| 7 | +import django |
7 | 8 | from django.db.models import QuerySet |
8 | 9 | from django.http import HttpResponse |
9 | 10 | from django.template import Template |
@@ -683,6 +684,49 @@ class TestTable(Table): |
683 | 684 | </table>""") |
684 | 685 |
|
685 | 686 |
|
| 687 | +@pytest.mark.skipif(django.VERSION[0] < 2, reason='This requires the new paginator API in django 2.0+') |
| 688 | +@pytest.mark.django_db |
| 689 | +def test_django_table_pagination_custom_paginator(): |
| 690 | + |
| 691 | + for x in range(30): |
| 692 | + Foo(a=x, b="foo").save() |
| 693 | + |
| 694 | + class TestTable(Table): |
| 695 | + a = Column.number(sortable=False) # turn off sorting to not get the link with random query params |
| 696 | + b = Column(show=False) # should still be able to filter on this though! |
| 697 | + |
| 698 | + from django.core.paginator import Paginator |
| 699 | + |
| 700 | + class CustomPaginator(Paginator): |
| 701 | + def __init__(self, object_list): |
| 702 | + super(CustomPaginator, self).__init__(object_list=object_list, per_page=2) |
| 703 | + |
| 704 | + def get_page(self, number): |
| 705 | + del number |
| 706 | + return self.page(2) |
| 707 | + |
| 708 | + data = Foo.objects.all().order_by('pk') |
| 709 | + verify_table_html( |
| 710 | + table=TestTable(data=data), |
| 711 | + paginator=CustomPaginator(data), |
| 712 | + expected_html=""" |
| 713 | + <table class="listview"> |
| 714 | + <thead> |
| 715 | + <tr> |
| 716 | + <th class="first_column subheader"> A </th> |
| 717 | + </tr> |
| 718 | + </thead> |
| 719 | + <tbody> |
| 720 | + <tr data-pk="3"> |
| 721 | + <td class="rj"> 2 </td> |
| 722 | + </tr> |
| 723 | + <tr data-pk="4"> |
| 724 | + <td class="rj"> 3 </td> |
| 725 | + </tr> |
| 726 | + </tbody> |
| 727 | + </table>""") |
| 728 | + |
| 729 | + |
686 | 730 | def test_links(): |
687 | 731 | class TestTable(NoSortTable): |
688 | 732 | foo = Column(header__attrs__title="Some title") |
|
0 commit comments