refactor: make pagination template compatible with ListView
This commit is contained in:
parent
97335e72bb
commit
54f11c74cb
|
@ -1,22 +1,22 @@
|
|||
{% if page.has_other_pages %}
|
||||
{% if is_paginated %}
|
||||
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
|
||||
{% if page.has_previous %}
|
||||
<a class="pagination-previous" href="?page={{ page.previous_page_number }}"><</a>
|
||||
{% if page_obj.has_previous %}
|
||||
<a class="pagination-previous" href="?page={{ page_obj.previous_page_number }}"><</a>
|
||||
{% else %}
|
||||
<a class="pagination-previous is-disabled"><</a>
|
||||
{% endif %}
|
||||
{% if page.has_next %}
|
||||
<a class="pagination-next" href="?page={{ page.next_page_number }}">></a>
|
||||
{% if page_obj.has_next %}
|
||||
<a class="pagination-next" href="?page={{ page_obj.next_page_number }}">></a>
|
||||
{% else %}
|
||||
<a class="pagination-next is-disabled">></a>
|
||||
{% endif %}
|
||||
<ul class="pagination-list">
|
||||
{% for p in page_range %}
|
||||
<li>
|
||||
{% if p == page.paginator.ELLIPSIS %}
|
||||
<span class="pagination-ellipsis">{{ page.paginator.ELLIPSIS }}</span>
|
||||
{% elif p == page.number %}
|
||||
<a class="pagination-link is-current">{{ p }}</a>
|
||||
{% if p == paginator.ELLIPSIS %}
|
||||
<span class="pagination-ellipsis">{{ paginator.ELLIPSIS }}</span>
|
||||
{% elif p == page_obj.number %}
|
||||
<span class="pagination-link is-current">{{ p }}</span>
|
||||
{% else %}
|
||||
<a class="pagination-link" href="?page={{ p }}">{{ p }}</a>
|
||||
{% endif %}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
{% block content %}
|
||||
<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 %}">
|
||||
<div class="message{% if not message.read %} is-info{% endif %} mb-5">
|
||||
<div class="message-header">
|
||||
|
|
|
@ -16,7 +16,7 @@ urlpatterns = [
|
|||
path("checkin/<int:pk>", views.checkin, name="checkin"),
|
||||
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("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/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"),
|
||||
|
|
|
@ -337,20 +337,21 @@ def delete_shiftregistration(request, pk):
|
|||
return redirect("team:shift", pk=spk)
|
||||
|
||||
|
||||
@login_required
|
||||
def incoming_messages(request):
|
||||
p = Paginator(IncomingMessage.objects.order_by("read", "-created_at"), 10)
|
||||
page = p.get_page(request.GET.get("page"))
|
||||
class IncomingMessagesList(LoginRequiredMixin, ListView):
|
||||
model = IncomingMessage
|
||||
paginate_by = 10
|
||||
template_name = "incoming_messages.html"
|
||||
|
||||
return render(
|
||||
request,
|
||||
"incoming_messages.html",
|
||||
{
|
||||
"num_unread": IncomingMessage.objects.filter(read=False).count(),
|
||||
"page": page,
|
||||
"page_range": p.get_elided_page_range(page.number),
|
||||
},
|
||||
)
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["num_unread"] = IncomingMessage.objects.filter(read=False).count()
|
||||
context["page_range"] = context["paginator"].get_elided_page_range(
|
||||
context["page_obj"].number
|
||||
)
|
||||
return context
|
||||
|
||||
def get_ordering(self):
|
||||
return ("read", "-created_at")
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in New Issue