2
0
Fork 0

feat(signage): add date parameter to team dashboard

This commit is contained in:
Luca 2024-05-25 02:11:46 +02:00
parent 33a07a0415
commit cbad7abfb7
1 changed files with 26 additions and 8 deletions

View File

@ -1,5 +1,6 @@
from datetime import timedelta
import datetime
from django.contrib import messages
from django.db import models
from django.db.models import Case, Count, ExpressionWrapper, F, Q, Sum, When
from django.shortcuts import render
@ -51,16 +52,31 @@ def public_dashboard(request):
def team_dashboard(request):
now = timezone.localtime()
changeover = now.replace(hour=6, minute=0, second=0, microsecond=0)
today = now.date()
if now.hour < changeover.hour:
day = None
exclude_past_shifts = True
if date := request.GET.get("date"):
try:
day = datetime.date.fromisoformat(date)
exclude_past_shifts = False
except ValueError:
messages.add_message(request, messages.ERROR, "Ungültiges Datum")
changeover = datetime.datetime.combine(
day or today, datetime.time(hour=6), timezone.get_current_timezone()
)
if day is None and now.hour < changeover.hour:
day_end = changeover
day_start = day_end - timedelta(days=1)
today = today - timedelta(days=1)
day_start = day_end - datetime.timedelta(days=1)
day = today - datetime.timedelta(days=1)
else:
day_start = changeover
day_end = day_start + timedelta(days=1)
day_end = day_start + datetime.timedelta(days=1)
if day is None:
day = today
team_shifts = (
Shift.with_reg_count()
@ -78,13 +94,15 @@ def team_dashboard(request):
deleted=False,
start_at__gte=day_start,
start_at__lt=day_end,
end_at__gt=now,
reg_count__lt=F("real_required_helpers"),
fallbackassignment_count__gt=0,
)
.order_by("start_at")
)
if exclude_past_shifts:
team_shifts = team_shifts.filter(end_at__gt=now)
return render(
request, "team_dashboard.html", {"today": today, "team_shifts": team_shifts}
request, "team_dashboard.html", {"today": day, "team_shifts": team_shifts}
)