feat: simplify pagination by using get_elided_page_range
This commit is contained in:
@@ -29,50 +29,28 @@
|
|||||||
<nav class="pagination" role="navigation" aria-label="pagination">
|
<nav class="pagination" role="navigation" aria-label="pagination">
|
||||||
|
|
||||||
{% if rescue_organizations_to_list.has_previous %}
|
{% if rescue_organizations_to_list.has_previous %}
|
||||||
<a class="pagination-previous" href="?page=1">« first</a>
|
<a class="pagination-previous"
|
||||||
<a href="?page={{ rescue_organizations_to_list.previous_page_number }}">previous</a>
|
href="?page={{ rescue_organizations_to_list.previous_page_number }}">previous</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if rescue_organizations_to_list.has_next %}
|
{% if rescue_organizations_to_list.has_next %}
|
||||||
<a class="pagination-next" href="?page={{ rescue_organizations_to_list.next_page_number }}">next</a>
|
<a class="pagination-next" href="?page={{ rescue_organizations_to_list.next_page_number }}">next</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<ul class="pagination-list">
|
<ul class="pagination-list">
|
||||||
{% if rescue_organizations_to_list.has_previous %}
|
{% for page in elided_page_range %}
|
||||||
<li>
|
{% if page != "…" %}
|
||||||
<a href="?page={{ rescue_organizations_to_list.previous_page_number }}"
|
<li>
|
||||||
class="pagination-link"
|
<a href="?page={{ page }}"
|
||||||
aria-label="Goto page {{ rescue_organizations_to_list.previous_page_number }}">
|
class="pagination-link {% if page == rescue_organizations_to_list.number %} is-current{% endif %}"
|
||||||
{{ rescue_organizations_to_list.previous_page_number }}
|
aria-label="Goto page {{ page }}">
|
||||||
</a>
|
{{ page }}
|
||||||
</li>
|
</a>
|
||||||
<li>
|
</li>
|
||||||
<span class="pagination-ellipsis">…</span>
|
{% else %}
|
||||||
</li>
|
<li>
|
||||||
{% endif %}
|
<span class="pagination-ellipsis">…</span>
|
||||||
<li>
|
</li>
|
||||||
<a
|
{% endif %}
|
||||||
class="pagination-link is-current"
|
{% endfor %}
|
||||||
aria-label="Page {{ rescue_organizations_to_list.number }}"
|
|
||||||
aria-current="page"
|
|
||||||
>{{ rescue_organizations_to_list.number }}</a
|
|
||||||
>
|
|
||||||
</li>
|
|
||||||
{% if rescue_organizations_to_list.has_next %}
|
|
||||||
<li>
|
|
||||||
<a href="?page={{ rescue_organizations_to_list.next_page_number }}"
|
|
||||||
class="pagination-link"
|
|
||||||
aria-label="Goto page {{ rescue_organizations_to_list.next_page_number }}">{{ rescue_organizations_to_list.next_page_number }}</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<span class="pagination-ellipsis">…</span>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="?page={{ rescue_organizations_to_list.paginator.num_pages }}"
|
|
||||||
class="pagination-link"
|
|
||||||
aria-label="Goto page {{ rescue_organizations_to_list.paginator.num_pages }}">
|
|
||||||
{{ rescue_organizations_to_list.paginator.num_pages }}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -699,7 +699,8 @@ def list_rescue_organizations(request, template='fellchensammlung/animal-shelter
|
|||||||
page_number = request.GET.get("page")
|
page_number = request.GET.get("page")
|
||||||
rescue_organizations_to_list = paginator.get_page(page_number)
|
rescue_organizations_to_list = paginator.get_page(page_number)
|
||||||
context = {"rescue_organizations_to_list": rescue_organizations_to_list,
|
context = {"rescue_organizations_to_list": rescue_organizations_to_list,
|
||||||
"show_rescue_orgs": True}
|
"show_rescue_orgs": True,
|
||||||
|
"elided_page_range": paginator.get_elided_page_range(page_number, on_each_side=2, on_ends=1)}
|
||||||
return render(request, template, context=context)
|
return render(request, template, context=context)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user