@ -1,5 +1,6 @@
from datetime import timedelta
import datetime
from django . contrib import messages
from django . db import models
from django . db import models
from django . db . models import Case , Count , ExpressionWrapper , F , Q , Sum , When
from django . db . models import Case , Count , ExpressionWrapper , F , Q , Sum , When
from django . shortcuts import render
from django . shortcuts import render
@ -51,16 +52,31 @@ def public_dashboard(request):
def team_dashboard ( request ) :
def team_dashboard ( request ) :
now = timezone . localtime ( )
now = timezone . localtime ( )
changeover = now . replace ( hour = 6 , minute = 0 , second = 0 , microsecond = 0 )
today = now . date ( )
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_end = changeover
day_start = day_end - timedelta ( days = 1 )
day_start = day_end - datetime. timedelta( days = 1 )
today = today - timedelta ( days = 1 )
day = today - datetime . timedelta ( days = 1 )
else :
else :
day_start = changeover
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 = (
team_shifts = (
Shift . with_reg_count ( )
Shift . with_reg_count ( )
@ -78,13 +94,15 @@ def team_dashboard(request):
deleted = False ,
deleted = False ,
start_at__gte = day_start ,
start_at__gte = day_start ,
start_at__lt = day_end ,
start_at__lt = day_end ,
end_at__gt = now ,
reg_count__lt = F ( " real_required_helpers " ) ,
reg_count__lt = F ( " real_required_helpers " ) ,
fallbackassignment_count__gt = 0 ,
fallbackassignment_count__gt = 0 ,
)
)
. order_by ( " start_at " )
. order_by ( " start_at " )
)
)
if exclude_past_shifts :
team_shifts = team_shifts . filter ( end_at__gt = now )
return render (
return render (
request , " team_dashboard.html " , { " today " : today , " team_shifts " : team_shifts }
request , " team_dashboard.html " , { " today " : day, " team_shifts " : team_shifts }
)
)