|
|
|
@ -3,6 +3,7 @@ from django.shortcuts import render
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
from .models import Helper, Shift, ShiftRegistration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def public_dashboard(request):
|
|
|
|
|
facts = []
|
|
|
|
|
|
|
|
|
@ -10,18 +11,35 @@ def public_dashboard(request):
|
|
|
|
|
if num_helpers > 0:
|
|
|
|
|
facts.append(("Registrierte Helfer*innen", num_helpers))
|
|
|
|
|
|
|
|
|
|
help_wanted = Q(required_helpers__gt=F("reg_count")) | Q(required_helpers=0) & Q(room__required_helpers__gt=F("reg_count"))
|
|
|
|
|
help_wanted = Q(required_helpers__gt=F("reg_count")) | Q(required_helpers=0) & Q(
|
|
|
|
|
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.filter(
|
|
|
|
|
state=ShiftRegistration.RegState.CHECKED_IN
|
|
|
|
|
).aggregate(sum=Sum("shift__duration"))["sum"]
|
|
|
|
|
if total_work_duration:
|
|
|
|
|
total_work_duration = round(total_work_duration.total_seconds() / 60.0)
|
|
|
|
|
facts.append(("Geleistete Personenstunden", f"{total_work_duration//60}h {total_work_duration%60}min"))
|
|
|
|
|
facts.append(
|
|
|
|
|
(
|
|
|
|
|
"Geleistete Personenstunden",
|
|
|
|
|
f"{total_work_duration//60}h {total_work_duration%60}min",
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
num_free_shifts = Shift.with_reg_count().filter(help_wanted, deleted=False, start_at__gte=timezone.now()).count()
|
|
|
|
|
num_free_shifts = (
|
|
|
|
|
Shift.with_reg_count()
|
|
|
|
|
.filter(help_wanted, deleted=False, start_at__gte=timezone.now())
|
|
|
|
|
.count()
|
|
|
|
|
)
|
|
|
|
|
if num_free_shifts > 0:
|
|
|
|
|
facts.append(("Zu übernehmende Schichten", num_free_shifts))
|
|
|
|
|
|
|
|
|
|
next_free_shifts = Shift.with_reg_count().filter(help_wanted, start_at__gt=timezone.now(), deleted=False).order_by("start_at")[:4]
|
|
|
|
|
next_free_shifts = (
|
|
|
|
|
Shift.with_reg_count()
|
|
|
|
|
.filter(help_wanted, start_at__gt=timezone.now(), deleted=False)
|
|
|
|
|
.order_by("start_at")[:4]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
context = {"facts": facts, "next_free_shifts": next_free_shifts}
|
|
|
|
|
return render(request, "public_dashboard.html", context)
|
|
|
|
|