Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed pagination when the number of pages is equal to page range plus one #655

Merged
merged 3 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django_tables2/templatetags/django_tables2.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def table_page_range(page, paginator):
if range_start < 1:
range_start = 1
range_end = range_start + page_range
if range_end >= num_pages:
if range_end > num_pages:
range_start = num_pages - page_range + 1
range_end = num_pages + 1

Expand Down
12 changes: 12 additions & 0 deletions tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ def test_table_page_range(self):
[1, "...", 93, 94, 95, 96, 97, 98, 99, 100],
)

def test_table_page_range_num_pages_equals_page_range_plus_one(self):
paginator = Paginator(range(1, 11 * 10), 10)
self.assertEqual(
table_page_range(paginator.page(1), paginator), [1, 2, 3, 4, 5, 6, 7, 8, "...", 11]
)
self.assertEqual(
table_page_range(paginator.page(6), paginator), [1, 2, 3, 4, 5, 6, 7, 8, "...", 11]
)
self.assertEqual(
table_page_range(paginator.page(7), paginator), [1, "...", 4, 5, 6, 7, 8, 9, 10, 11]
)

def test_table_page_range_lazy(self):
paginator = LazyPaginator(range(1, 1000), 10)

Expand Down