Skip to content

Commit

Permalink
views: Reverse pagination naming
Browse files Browse the repository at this point in the history
The leading_set contained the page numbers that should be shown trailing
(i.e. on the right of the paginator). This was confusing. Correct it.

Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Nov 4, 2024
1 parent 8c7aed3 commit 3c5f632
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions patchwork/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, request, objects):
if request.user.is_authenticated:
items_per_page = request.user.profile.items_per_page

super(Paginator, self).__init__(objects, items_per_page)
super().__init__(objects, items_per_page)

try:
page_no = int(request.GET.get('page', 1))
Expand All @@ -52,23 +52,25 @@ def __init__(self, request, objects):
elif page_no < LEADING_PAGE_RANGE:
adjacent_start = 1
adjacent_end = LEADING_PAGE_RANGE_DISPLAYED + 1
self.leading_set = [
n + pages for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)
self.trailing_set = [
n + pages
for n in reversed(range(0, -NUM_PAGES_OUTSIDE_RANGE, -1))
]
elif page_no >= pages - TRAILING_PAGE_RANGE:
adjacent_start = pages - TRAILING_PAGE_RANGE_DISPLAYED + 1
adjacent_end = pages + 1
self.trailing_set = [
self.leading_set = [
n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)
]
else:
adjacent_start = page_no - ADJACENT_PAGES
adjacent_end = page_no + ADJACENT_PAGES + 1
self.leading_set = [
n + pages for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)
n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)
]
self.trailing_set = [
n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)
n + pages
for n in reversed(range(0, -NUM_PAGES_OUTSIDE_RANGE, -1))
]

self.adjacent_set = [
Expand All @@ -77,7 +79,6 @@ def __init__(self, request, objects):
if n > 0 and n <= pages
]

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

{% if page.paginator.trailing_set %}
{% for p in page.paginator.trailing_set %}
{% if page.paginator.leading_set %}
{% for p in page.paginator.leading_set %}
<span class="page"><a href="{% listurl page=p %}" >{{ p }}</a></span>
{% endfor %}
Expand All @@ -25,9 +25,9 @@
{% endif %}
{% endfor %}

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

0 comments on commit 3c5f632

Please sign in to comment.