]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
view: Show pagination ellipsis only when needed
authorStephen Finucane <stephen@that.guru>
Mon, 4 Nov 2024 20:42:16 +0000 (20:42 +0000)
committerStephen Finucane <stephen@that.guru>
Mon, 4 Nov 2024 21:05:10 +0000 (21:05 +0000)
Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #614
patchwork/paginator.py
patchwork/templates/patchwork/partials/pagination.html

index 5a9e52edc0231adb538a5f2735db419bd3ef74e1..1b7bd9145f16e1c91a7f14021e53d25dff117e32 100644 (file)
@@ -79,6 +79,18 @@ class Paginator(paginator.Paginator):
             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
         )
index 94be806d2766f237e2535c242e16eb0dfa163c1b..8048370d66b38a4fb424d945c39f2a35d2347104 100644 (file)
   <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 %}
 
 {% 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">