From 84e944ae673f1ac3318f3cc347f2323871325440 Mon Sep 17 00:00:00 2001 From: "Andreas (@xAndy) Zimmermann" Date: Mon, 8 May 2023 23:37:17 +0200 Subject: [PATCH] add team per room view, sort overview rooms --- .../team/templates/shift_detail.html | 4 ++- .../team/templates/shift_overview.html | 2 +- shiftregister/team/urls.py | 1 + shiftregister/team/views.py | 28 +++++++++++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/shiftregister/team/templates/shift_detail.html b/shiftregister/team/templates/shift_detail.html index 813f23e..038d269 100644 --- a/shiftregister/team/templates/shift_detail.html +++ b/shiftregister/team/templates/shift_detail.html @@ -3,7 +3,9 @@ {% block title %}Schichtdetails{% endblock %} {% block content %} -

{% if shift.deleted %}(gelöscht) {% endif %}{{ shift.room.name }} {{ shift.start_at }} ({{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }})

+

{% if shift.deleted %}(gelöscht) {% endif %} + {{ shift.room.name }} + {{ shift.start_at }} ({{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }})

{% if shift.room.description %}
Beschreibung: diff --git a/shiftregister/team/templates/shift_overview.html b/shiftregister/team/templates/shift_overview.html index bdf68ee..ddd7aae 100644 --- a/shiftregister/team/templates/shift_overview.html +++ b/shiftregister/team/templates/shift_overview.html @@ -16,7 +16,7 @@
{% for shift in next_shifts %}
-
{{ shift.room.name }}
+
{{ shift.room.name }}
{% include "partials/shift_box.html" %} diff --git a/shiftregister/team/urls.py b/shiftregister/team/urls.py index 2ca83eb..f8a4296 100644 --- a/shiftregister/team/urls.py +++ b/shiftregister/team/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ path("", views.shift_overview, name="index"), path("overview/", views.shift_overview, name="shift_overview"), path("shifts/", views.ShiftList.as_view(), name="shift_all"), + path("room_shifts/", views.RoomShiftList.as_view(), name="shift_room"), path("free_shifts/", views.FreeShiftList.as_view(), name="shift_free"), path("shift/", views.shift_detail, name="shift"), path("helper/", views.HelperDetail.as_view(), name="helper"), diff --git a/shiftregister/team/views.py b/shiftregister/team/views.py index 5407426..0683684 100644 --- a/shiftregister/team/views.py +++ b/shiftregister/team/views.py @@ -40,7 +40,7 @@ def shift_overview(request): Shift.objects.filter(room=room, start_at__gt=timezone.now(), deleted=False) .order_by("start_at") .first() - for room in Room.objects.all() + for room in Room.objects.all().order_by("name") ), ) @@ -187,7 +187,7 @@ class ShiftList(LoginRequiredMixin, ListView): return context def get_ordering(self): - return ("start_at", "room_id") + return ("start_at", "room__name") class FreeShiftList(ShiftList): @@ -210,7 +210,29 @@ class FreeShiftList(ShiftList): end_at__gte=timezone.now(), deleted=False, ) - .order_by("start_at", "room_id") + .order_by("start_at", "room__name") + ) + + +class RoomShiftList(ShiftList): + def get_context_data(self, **kwargs): + room = get_object_or_404(Room, pk=self.kwargs["pk"]) + context = super().get_context_data(**kwargs) + context["title"] = f"Schichten fuer {room.name}" + return context + + def get_queryset(self): + room = get_object_or_404(Room, pk=self.kwargs["pk"]) + help_wanted = Q(required_helpers__gt=F("reg_count")) | Q( + required_helpers=0 + ) & Q(room__required_helpers__gt=F("reg_count")) + return ( + Shift.with_reg_count() + .filter( + deleted=False, + room=room, + ) + .order_by("start_at", "room__name") )