feat: basic pagination

This commit is contained in:
2025-07-03 19:40:52 +02:00
parent 24bae28cec
commit 165aeb6dcc
2 changed files with 58 additions and 2 deletions

View File

@@ -22,6 +22,57 @@
</div> </div>
</div> </div>
<div class="block"> <div class="block">
{% include "fellchensammlung/lists/list-animal-shelters.html" %} {% with rescue_organizations=rescue_organizations_to_list %}
{% include "fellchensammlung/lists/list-animal-shelters.html" %}
{% endwith %}
</div> </div>
<nav class="pagination" role="navigation" aria-label="pagination">
{% if rescue_organizations_to_list.has_previous %}
<a class="pagination-previous" href="?page=1">&laquo; first</a>
<a href="?page={{ rescue_organizations_to_list.previous_page_number }}">previous</a>
{% endif %}
{% if rescue_organizations_to_list.has_next %}
<a class="pagination-next" href="?page={{ rescue_organizations_to_list.next_page_number }}">next</a>
{% endif %}
<ul class="pagination-list">
{% if rescue_organizations_to_list.has_previous %}
<li>
<a href="?page={{ rescue_organizations_to_list.previous_page_number }}"
class="pagination-link"
aria-label="Goto page {{ rescue_organizations_to_list.previous_page_number }}">
{{ rescue_organizations_to_list.previous_page_number }}
</a>
</li>
<li>
<span class="pagination-ellipsis">&hellip;</span>
</li>
{% endif %}
<li>
<a
class="pagination-link is-current"
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">&hellip;</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>
</nav>
{% endblock %} {% endblock %}

View File

@@ -2,6 +2,7 @@ import logging
from datetime import timedelta from datetime import timedelta
from django.contrib.auth.views import redirect_to_login from django.contrib.auth.views import redirect_to_login
from django.core.paginator import Paginator
from django.http import HttpResponseRedirect, JsonResponse, HttpResponse from django.http import HttpResponseRedirect, JsonResponse, HttpResponse
from django.http.response import HttpResponseForbidden from django.http.response import HttpResponseForbidden
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
@@ -693,7 +694,11 @@ def external_site_warning(request, template_name='fellchensammlung/external-site
def list_rescue_organizations(request, template='fellchensammlung/animal-shelters.html'): def list_rescue_organizations(request, template='fellchensammlung/animal-shelters.html'):
rescue_organizations = RescueOrganization.objects.all() rescue_organizations = RescueOrganization.objects.all()
context = {"rescue_organizations": rescue_organizations, paginator = Paginator(rescue_organizations, 25)
page_number = request.GET.get("page")
rescue_organizations_to_list = paginator.get_page(page_number)
context = {"rescue_organizations_to_list": rescue_organizations_to_list,
"show_rescue_orgs": True} "show_rescue_orgs": True}
return render(request, template, context=context) return render(request, template, context=context)