feat: improve public dashboard
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Luca 2025-05-18 16:00:43 +02:00
parent 2bb564ebce
commit 8e9ef718b8
2 changed files with 61 additions and 52 deletions

View File

@ -3,16 +3,16 @@
{% load qrcode %}
{% block everything %}
<section class="hero">
<main class="is-flex is-flex-direction-column is-flex-grow-1 is-justify-content-center">
<section class="hero">
<div class="hero-body">
<div class="container has-text-centered">
<h2 class="title is-2">kontakt &ndash; das Kulturfestival</h2>
<h1 class="title is-1">sucht dich!</h1>
<h3 class="title">Schnapp dir deine Helfischicht auf https://helfen.kntkt.de</h3>
<h2 class="title is-1">kontakt &ndash; das Kulturfestival</h2>
<h1 class="title is-2">sucht dich!</h1>
</div>
</div>
</section>
<section class="hero is-link is-small">
</section>
<section class="hero is-link is-small">
<div class="hero-body">
<div class="container">
<div class="level">
@ -27,24 +27,20 @@
</div>
</div>
</div>
</section>
<section class="section">
<div class="container">
<h3 class="title">Nächste freie Schichten</h3>
<div class="columns">
{% for shift in next_free_shifts %}
<div class="column has-text-centered is-quarter">
<div class="box">
<div class="content">
<p class="is-size-4">{{ shift.start_at }}</p>
</section>
<section class="hero">
<div class="hero-body">
<div class="container has-text-centered">
<h3 class="title">
Schnapp dir deine Helfischicht!
</h3>
{% url 'shift' shift.pk as shift_url %}
{% qrcode "https://helfen.kntkt.de"|add:shift_url %}
<p class="is-size-4 mt-4">{{ shift.room.name }}</p>
{% qrcode "https://helfen.kntkt.de" %}
<h3 class="title mt-3">
https://helfen.kntkt.de
</h3>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</section>
</section>
</main>
{% endblock %}

View File

@ -5,9 +5,12 @@ from django.db import models
from django.db.models import Case, Count, ExpressionWrapper, F, Q, Sum, When
from django.shortcuts import render
from django.utils import timezone
from dynamic_preferences.registries import global_preferences_registry
from .models import Helper, Shift, ShiftRegistration
global_preferences = global_preferences_registry.manager()
def public_dashboard(request):
facts = []
@ -20,9 +23,17 @@ def public_dashboard(request):
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.annotate(
shift__end_at=F("shift__start_at") + F("shift__duration")
)
.filter(
state=ShiftRegistration.RegState.CHECKED_IN,
shift__start_at__gte=global_preferences["helper__event_start_at"],
shift__end_at__lte=global_preferences["helper__event_end_at"],
)
.aggregate(sum=Sum("shift__duration"))["sum"]
)
if total_work_duration:
total_work_duration = round(total_work_duration.total_seconds() / 60.0)
facts.append(
@ -32,21 +43,23 @@ def public_dashboard(request):
)
)
num_free_shifts = (
free_slots = (
Shift.objects.with_reg_count()
.filter(help_wanted, start_at__gte=timezone.now())
.count()
.annotate(
end_at=F("start_at") + F("duration"),
free_slots=Case(
When(required_helpers=0, then=F("room__required_helpers")),
default=F("required_helpers"),
)
if num_free_shifts > 0:
facts.append(("Zu übernehmende Schichten", num_free_shifts))
next_free_shifts = (
Shift.objects.with_reg_count()
.filter(help_wanted, start_at__gt=timezone.now())
.order_by("start_at")[:4]
- F("reg_count"),
)
.filter(end_at__gt=timezone.now(), free_slots__gt=0)
.aggregate(sum=Sum("free_slots"))["sum"]
)
if free_slots:
facts.append(("Benötigte Helfis", free_slots))
context = {"facts": facts, "next_free_shifts": next_free_shifts}
context = {"facts": facts}
return render(request, "public_dashboard.html", context)