From e007e67e83b9fbc331241342460d8fba70c1897a Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 17 May 2023 13:41:01 +0200 Subject: [PATCH] Add basic team dashboard --- .../signage/templates/team_dashboard.html | 27 ++++++++++++++++ shiftregister/signage/urls.py | 1 + shiftregister/signage/views.py | 31 ++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 shiftregister/signage/templates/team_dashboard.html diff --git a/shiftregister/signage/templates/team_dashboard.html b/shiftregister/signage/templates/team_dashboard.html new file mode 100644 index 0000000..3895dc1 --- /dev/null +++ b/shiftregister/signage/templates/team_dashboard.html @@ -0,0 +1,27 @@ +{% extends "autoscroll.html" %} + +{% block everything %} +
+
+

Teamschichten für {{ today|date:"l, d. F Y" }}

+ + + + + + + + + +{% for shift in team_shifts %} + + + + + +{% endfor %} + +
SchichtStartzeitTeammitglied(er)
{{ shift.room.name }}{{ shift.start_at }}{% for fa in shift.fallbackassignment_set.all %}{{ fa.team_member.name }}{% if not forloop.last %}, {% endif %}{% endfor %}
+
+
+{% endblock %} diff --git a/shiftregister/signage/urls.py b/shiftregister/signage/urls.py index 0c5a506..e96e33c 100644 --- a/shiftregister/signage/urls.py +++ b/shiftregister/signage/urls.py @@ -5,4 +5,5 @@ from . import views app_name = "signage" urlpatterns = [ path("public/", views.public_dashboard, name="public_dashboard"), + path("team/", views.team_dashboard, name="team_dashboard"), ] diff --git a/shiftregister/signage/views.py b/shiftregister/signage/views.py index b4c1578..6db8859 100644 --- a/shiftregister/signage/views.py +++ b/shiftregister/signage/views.py @@ -1,4 +1,5 @@ -from django.db.models import F, Q, Sum +from datetime import timedelta +from django.db.models import Case, Count, F, Q, Sum, When from django.shortcuts import render from django.utils import timezone from .models import Helper, Shift, ShiftRegistration @@ -43,3 +44,31 @@ def public_dashboard(request): context = {"facts": facts, "next_free_shifts": next_free_shifts} return render(request, "public_dashboard.html", context) + + +def team_dashboard(request): + today = timezone.now().date() + + team_shifts = ( + Shift.with_reg_count() + .annotate( + real_required_helpers=Case( + When(required_helpers=0, then=F("room__required_helpers")), + default=F("required_helpers"), + ), + fallbackassignment_count=Count("fallbackassignment"), + ) + .filter( + deleted=False, + start_at__gt=today + timedelta(hours=6), + start_at__lte=today + timedelta(hours=30), + start_at__gte=timezone.now(), + reg_count__lt=F("real_required_helpers"), + fallbackassignment_count__gt=0, + ) + .order_by("start_at") + ) + + return render( + request, "team_dashboard.html", {"today": today, "team_shifts": team_shifts} + )