Merge pull request #1036 from SavinaRoja/pagination-list

pagination list navigation using a range of pages such as provided by get_elided_page_range
This commit is contained in:
Mouse Reeve 2021-05-03 10:57:38 -07:00 committed by GitHub
commit 93959fc600
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -1,5 +1,5 @@
{% load i18n %} {% load i18n %}
<nav class="pagination" aria-label="pagination"> <nav class="pagination is-centered" aria-label="pagination">
<a <a
class="pagination-previous {% if not page.has_previous %}is-disabled{% endif %}" class="pagination-previous {% if not page.has_previous %}is-disabled{% endif %}"
{% if page.has_previous %} {% if page.has_previous %}
@ -23,4 +23,18 @@
{% trans "Next" %} {% trans "Next" %}
<span class="icon icon-arrow-right" aria-hidden="true"></span> <span class="icon icon-arrow-right" aria-hidden="true"></span>
</a> </a>
{% if page.has_other_pages and page_range %}
<ul class="pagination-list">
{% for num in page_range %}
{% if num == page.number %}
<li><a class="pagination-link is-current" aria-label="Page {{ num }}" aria-current="page">{{ num }}</a></li>
{% elif num == '…' %}
<li><span class="pagination-ellipsis">&hellip;</span></li>
{% else %}
<li><a class="pagination-link" aria-label="Goto page {{ num }}" href="{{ path }}?{% for k, v in request.GET.items %}{% if k != 'page' %}{{ k }}={{ v }}&{% endif %}{% endfor %}page={{ num }}{{ anchor }}">{{ num }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
</nav> </nav>

View file

@ -156,9 +156,13 @@ class List(View):
).order_by("-updated_date") ).order_by("-updated_date")
][: 5 - len(suggestions)] ][: 5 - len(suggestions)]
page = paginated.get_page(request.GET.get("page"))
data = { data = {
"list": book_list, "list": book_list,
"items": paginated.get_page(request.GET.get("page")), "items": page,
"page_range": paginated.get_elided_page_range(
page.number, on_each_side=2, on_ends=1
),
"pending_count": book_list.listitem_set.filter(approved=False).count(), "pending_count": book_list.listitem_set.filter(approved=False).count(),
"suggested_books": suggestions, "suggested_books": suggestions,
"list_form": forms.ListForm(instance=book_list), "list_form": forms.ListForm(instance=book_list),