Skip to content

Commit

Permalink
view: Show pagination ellipsis only when needed
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Finucane <[email protected]>
Closes: #614
  • Loading branch information
stephenfin committed Nov 4, 2024
1 parent 3c5f632 commit 16d23ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions patchwork/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ def __init__(self, request, objects):
if n > 0 and n <= pages
]

self.show_leading_ellipsis = False
if self.leading_set and self.adjacent_set:
# prevent e.g. 1 2 ... 3 4 5 ... 8 9
if self.leading_set[-1] != self.adjacent_set[0] - 1:
self.show_leading_ellipsis = True

self.show_trailing_ellipsis = False
if self.trailing_set and self.adjacent_set:
# prevent e.g. 1 2 ... 5 6 7 ... 8 9
if self.trailing_set[0] != self.adjacent_set[-1] + 1:
self.show_trailing_ellipsis = True

self.long_page = (
len(self.current_page.object_list) >= LONG_PAGE_THRESHOLD
)
6 changes: 3 additions & 3 deletions patchwork/templates/patchwork/partials/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<span class="prev-na">&laquo;</span>
{% endif %}

{% if page.paginator.leading_set %}
{% for p in page.paginator.leading_set %}
<span class="page"><a href="{% listurl page=p %}" >{{ p }}</a></span>
{% endfor %}
{% if page.paginator.show_leading_ellipsis %}
{% endif %}

Expand All @@ -25,12 +25,12 @@
{% endif %}
{% endfor %}

{% if page.paginator.trailing_set %}
{% if page.paginator.show_trailing_ellipsis %}
{% endif %}
{% for p in page.paginator.trailing_set %}
<span class="page"><a href="{% listurl page=p %}">{{ p }}</a></span>
{% endfor %}
{% endif %}

{% if page.has_next %}
<span class="next">
Expand Down

0 comments on commit 16d23ea

Please sign in to comment.