2
0
Fork 0

refactor: make pagination template compatible with ListView

This commit is contained in:
Luca 2024-05-14 22:58:20 +02:00
parent 97335e72bb
commit 54f11c74cb
4 changed files with 25 additions and 24 deletions

View File

@ -1,22 +1,22 @@
{% if page.has_other_pages %} {% if is_paginated %}
<nav class="pagination is-centered" role="navigation" aria-label="pagination"> <nav class="pagination is-centered" role="navigation" aria-label="pagination">
{% if page.has_previous %} {% if page_obj.has_previous %}
<a class="pagination-previous" href="?page={{ page.previous_page_number }}">&lt;</a> <a class="pagination-previous" href="?page={{ page_obj.previous_page_number }}">&lt;</a>
{% else %} {% else %}
<a class="pagination-previous is-disabled">&lt;</a> <a class="pagination-previous is-disabled">&lt;</a>
{% endif %} {% endif %}
{% if page.has_next %} {% if page_obj.has_next %}
<a class="pagination-next" href="?page={{ page.next_page_number }}">&gt;</a> <a class="pagination-next" href="?page={{ page_obj.next_page_number }}">&gt;</a>
{% else %} {% else %}
<a class="pagination-next is-disabled">&gt;</a> <a class="pagination-next is-disabled">&gt;</a>
{% endif %} {% endif %}
<ul class="pagination-list"> <ul class="pagination-list">
{% for p in page_range %} {% for p in page_range %}
<li> <li>
{% if p == page.paginator.ELLIPSIS %} {% if p == paginator.ELLIPSIS %}
<span class="pagination-ellipsis">{{ page.paginator.ELLIPSIS }}</span> <span class="pagination-ellipsis">{{ paginator.ELLIPSIS }}</span>
{% elif p == page.number %} {% elif p == page_obj.number %}
<a class="pagination-link is-current">{{ p }}</a> <span class="pagination-link is-current">{{ p }}</span>
{% else %} {% else %}
<a class="pagination-link" href="?page={{ p }}">{{ p }}</a> <a class="pagination-link" href="?page={{ p }}">{{ p }}</a>
{% endif %} {% endif %}

View File

@ -7,7 +7,7 @@
{% block content %} {% block content %}
<h3 class="title">Eingehende Nachrichten</h3> <h3 class="title">Eingehende Nachrichten</h3>
{% for message in page %} {% for message in page_obj %}
<a href="{% if message.from_helper %}{% url 'team:helper' message.from_helper.pk %}#history{% else %}{% url 'team:incoming_message' message.pk %}{% endif %}"> <a href="{% if message.from_helper %}{% url 'team:helper' message.from_helper.pk %}#history{% else %}{% url 'team:incoming_message' message.pk %}{% endif %}">
<div class="message{% if not message.read %} is-info{% endif %} mb-5"> <div class="message{% if not message.read %} is-info{% endif %} mb-5">
<div class="message-header"> <div class="message-header">

View File

@ -16,7 +16,7 @@ urlpatterns = [
path("checkin/<int:pk>", views.checkin, name="checkin"), path("checkin/<int:pk>", views.checkin, name="checkin"),
path("mark_as_failed/<int:pk>", views.mark_as_failed, name="mark_as_failed"), path("mark_as_failed/<int:pk>", views.mark_as_failed, name="mark_as_failed"),
path("remove_helper/<int:pk>", views.delete_shiftregistration, name="unregister"), path("remove_helper/<int:pk>", views.delete_shiftregistration, name="unregister"),
path("incoming/", views.incoming_messages, name="incoming_messages"), path("incoming/", views.IncomingMessagesList.as_view(), name="incoming_messages"),
path("incoming/<slug:pk>", views.incoming_message, name="incoming_message"), path("incoming/<slug:pk>", views.incoming_message, name="incoming_message"),
path("incoming/mark_as_read/<slug:pk>", views.mark_as_read, name="mark_as_read"), path("incoming/mark_as_read/<slug:pk>", views.mark_as_read, name="mark_as_read"),
path("list/<slug:token>", views.room_view_token, name="room_view_token"), path("list/<slug:token>", views.room_view_token, name="room_view_token"),

View File

@ -337,20 +337,21 @@ def delete_shiftregistration(request, pk):
return redirect("team:shift", pk=spk) return redirect("team:shift", pk=spk)
@login_required class IncomingMessagesList(LoginRequiredMixin, ListView):
def incoming_messages(request): model = IncomingMessage
p = Paginator(IncomingMessage.objects.order_by("read", "-created_at"), 10) paginate_by = 10
page = p.get_page(request.GET.get("page")) template_name = "incoming_messages.html"
return render( def get_context_data(self, **kwargs):
request, context = super().get_context_data(**kwargs)
"incoming_messages.html", context["num_unread"] = IncomingMessage.objects.filter(read=False).count()
{ context["page_range"] = context["paginator"].get_elided_page_range(
"num_unread": IncomingMessage.objects.filter(read=False).count(), context["page_obj"].number
"page": page, )
"page_range": p.get_elided_page_range(page.number), return context
},
) def get_ordering(self):
return ("read", "-created_at")
@login_required @login_required