Skip to content

Commit 16d23ea

Browse files
committed
view: Show pagination ellipsis only when needed
Signed-off-by: Stephen Finucane <[email protected]> Closes: getpatchwork#614
1 parent 3c5f632 commit 16d23ea

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

patchwork/paginator.py

+12
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ def __init__(self, request, objects):
7979
if n > 0 and n <= pages
8080
]
8181

82+
self.show_leading_ellipsis = False
83+
if self.leading_set and self.adjacent_set:
84+
# prevent e.g. 1 2 ... 3 4 5 ... 8 9
85+
if self.leading_set[-1] != self.adjacent_set[0] - 1:
86+
self.show_leading_ellipsis = True
87+
88+
self.show_trailing_ellipsis = False
89+
if self.trailing_set and self.adjacent_set:
90+
# prevent e.g. 1 2 ... 5 6 7 ... 8 9
91+
if self.trailing_set[0] != self.adjacent_set[-1] + 1:
92+
self.show_trailing_ellipsis = True
93+
8294
self.long_page = (
8395
len(self.current_page.object_list) >= LONG_PAGE_THRESHOLD
8496
)

patchwork/templates/patchwork/partials/pagination.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<span class="prev-na">&laquo;</span>
1111
{% endif %}
1212

13-
{% if page.paginator.leading_set %}
1413
{% for p in page.paginator.leading_set %}
1514
<span class="page"><a href="{% listurl page=p %}" >{{ p }}</a></span>
1615
{% endfor %}
16+
{% if page.paginator.show_leading_ellipsis %}
1717
1818
{% endif %}
1919

@@ -25,12 +25,12 @@
2525
{% endif %}
2626
{% endfor %}
2727

28-
{% if page.paginator.trailing_set %}
28+
{% if page.paginator.show_trailing_ellipsis %}
2929
30+
{% endif %}
3031
{% for p in page.paginator.trailing_set %}
3132
<span class="page"><a href="{% listurl page=p %}">{{ p }}</a></span>
3233
{% endfor %}
33-
{% endif %}
3434

3535
{% if page.has_next %}
3636
<span class="next">

0 commit comments

Comments
 (0)