|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
from datetime import timedelta
|
|
|
|
|
from django.db.models import Case, Count, F, Q, Sum, When
|
|
|
|
|
from django.db import models
|
|
|
|
|
from django.db.models import Case, Count, F, ExpressionWrapper, Q, Sum, When
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
from .models import Helper, Shift, ShiftRegistration
|
|
|
|
@ -47,11 +48,24 @@ def public_dashboard(request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def team_dashboard(request):
|
|
|
|
|
today = timezone.now().date()
|
|
|
|
|
now = timezone.localtime()
|
|
|
|
|
changeover = now.replace(hour=6, minute=0, second=0, microsecond=0)
|
|
|
|
|
today = now.date()
|
|
|
|
|
|
|
|
|
|
if now.hour < changeover.hour:
|
|
|
|
|
day_end = changeover
|
|
|
|
|
day_start = day_end - timedelta(days=1)
|
|
|
|
|
today = today - timedelta(days=1)
|
|
|
|
|
else:
|
|
|
|
|
day_start = changeover
|
|
|
|
|
day_end = day_start + timedelta(days=1)
|
|
|
|
|
|
|
|
|
|
team_shifts = (
|
|
|
|
|
Shift.with_reg_count()
|
|
|
|
|
.annotate(
|
|
|
|
|
end_at=ExpressionWrapper(
|
|
|
|
|
F("start_at") + F("duration"), output_field=models.DateTimeField()
|
|
|
|
|
),
|
|
|
|
|
real_required_helpers=Case(
|
|
|
|
|
When(required_helpers=0, then=F("room__required_helpers")),
|
|
|
|
|
default=F("required_helpers"),
|
|
|
|
@ -60,9 +74,9 @@ def team_dashboard(request):
|
|
|
|
|
)
|
|
|
|
|
.filter(
|
|
|
|
|
deleted=False,
|
|
|
|
|
start_at__gt=today + timedelta(hours=6),
|
|
|
|
|
start_at__lte=today + timedelta(hours=30),
|
|
|
|
|
start_at__gte=timezone.now(),
|
|
|
|
|
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,
|
|
|
|
|
)
|
|
|
|
|