From 8e9ef718b8ccf33dac447b644efe1e61aad92062 Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 18 May 2025 16:00:43 +0200 Subject: [PATCH] feat: improve public dashboard --- .../signage/templates/public_dashboard.html | 70 +++++++++---------- shiftregister/signage/views.py | 43 ++++++++---- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/shiftregister/signage/templates/public_dashboard.html b/shiftregister/signage/templates/public_dashboard.html index 0974ec6..2ffffd5 100644 --- a/shiftregister/signage/templates/public_dashboard.html +++ b/shiftregister/signage/templates/public_dashboard.html @@ -3,48 +3,44 @@ {% load qrcode %} {% block everything %} -
-
-
-

kontakt – das Kulturfestival

-

sucht dich!

-

Schnapp dir deine Helfischicht auf https://helfen.kntkt.de

+
+
+
+
+

kontakt – das Kulturfestival

+

sucht dich!

+
-
-
- + -
-
-

Nächste freie Schichten

-
-{% for shift in next_free_shifts %} -
-
-
-

{{ shift.start_at }}

- {% url 'shift' shift.pk as shift_url %} - {% qrcode "https://helfen.kntkt.de"|add:shift_url %} -

{{ shift.room.name }}

-
-{% endfor %}
-
-
+ +
+
+
+

+ Schnapp dir deine Helfischicht! +

+ {% url 'shift' shift.pk as shift_url %} + {% qrcode "https://helfen.kntkt.de" %} +

+ https://helfen.kntkt.de +

+
+
+
+ {% endblock %} diff --git a/shiftregister/signage/views.py b/shiftregister/signage/views.py index c1bb3a8..570d53c 100644 --- a/shiftregister/signage/views.py +++ b/shiftregister/signage/views.py @@ -5,9 +5,12 @@ from django.db import models from django.db.models import Case, Count, ExpressionWrapper, F, Q, Sum, When from django.shortcuts import render from django.utils import timezone +from dynamic_preferences.registries import global_preferences_registry from .models import Helper, Shift, ShiftRegistration +global_preferences = global_preferences_registry.manager() + def public_dashboard(request): facts = [] @@ -20,9 +23,17 @@ def public_dashboard(request): room__required_helpers__gt=F("reg_count") ) - total_work_duration = ShiftRegistration.objects.filter( - state=ShiftRegistration.RegState.CHECKED_IN - ).aggregate(sum=Sum("shift__duration"))["sum"] + total_work_duration = ( + ShiftRegistration.objects.annotate( + shift__end_at=F("shift__start_at") + F("shift__duration") + ) + .filter( + state=ShiftRegistration.RegState.CHECKED_IN, + shift__start_at__gte=global_preferences["helper__event_start_at"], + shift__end_at__lte=global_preferences["helper__event_end_at"], + ) + .aggregate(sum=Sum("shift__duration"))["sum"] + ) if total_work_duration: total_work_duration = round(total_work_duration.total_seconds() / 60.0) facts.append( @@ -32,21 +43,23 @@ def public_dashboard(request): ) ) - num_free_shifts = ( + free_slots = ( Shift.objects.with_reg_count() - .filter(help_wanted, start_at__gte=timezone.now()) - .count() + .annotate( + end_at=F("start_at") + F("duration"), + free_slots=Case( + When(required_helpers=0, then=F("room__required_helpers")), + default=F("required_helpers"), + ) + - F("reg_count"), + ) + .filter(end_at__gt=timezone.now(), free_slots__gt=0) + .aggregate(sum=Sum("free_slots"))["sum"] ) - if num_free_shifts > 0: - facts.append(("Zu übernehmende Schichten", num_free_shifts)) + if free_slots: + facts.append(("Benötigte Helfis", free_slots)) - next_free_shifts = ( - Shift.objects.with_reg_count() - .filter(help_wanted, start_at__gt=timezone.now()) - .order_by("start_at")[:4] - ) - - context = {"facts": facts, "next_free_shifts": next_free_shifts} + context = {"facts": facts} return render(request, "public_dashboard.html", context)