Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
to avoid excessively long page lists
- Loading branch information
Torsten Rehn
committed
Apr 15, 2015
1 parent
dc74fd1
commit 10c00f6
Showing
3 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
20 changes: 20 additions & 0 deletions
20
src/teamvault/apps/secrets/templatetags/smart_pagination.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
|
||
@register.filter | ||
def smart_pages(all_pages, current_page): | ||
all_pages = list(all_pages) | ||
smart_pages = set([ | ||
1, | ||
all_pages[-1], | ||
current_page, | ||
max(min(current_page // 2, all_pages[-1]), 1), | ||
max(min(current_page + ((all_pages[-1] - current_page) // 2), all_pages[-1]), 1), | ||
max(min(current_page + 1, all_pages[-1]), 1), | ||
max(min(current_page + 2, all_pages[-1]), 1), | ||
max(min(current_page - 1, all_pages[-1]), 1), | ||
max(min(current_page - 2, all_pages[-1]), 1), | ||
]) | ||
return sorted(smart_pages) |