diff --git a/shiftregister/team/templates/partials/shift_box.html b/shiftregister/team/templates/partials/shift_box.html index 822b034..189461b 100644 --- a/shiftregister/team/templates/partials/shift_box.html +++ b/shiftregister/team/templates/partials/shift_box.html @@ -7,8 +7,12 @@ Beginn: {{ shift.start_at }}
Dauer: {{ shift.duration }}
Belegung: {{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }} +{% if shift.checkin_count is not None %} +
+ Checkin-Status: {% if shift.checkin_count == shift.required_helpers|default:shift.room.required_helpers %}vollständig{% elif shift.checkin_count > 0 %}teilweise{% else %}kein Checkin{% endif %} +{% endif %} -
- Details +
+ Details
diff --git a/shiftregister/team/templates/shift_overview.html b/shiftregister/team/templates/shift_overview.html index ddd7aae..0f4aa6c 100644 --- a/shiftregister/team/templates/shift_overview.html +++ b/shiftregister/team/templates/shift_overview.html @@ -12,12 +12,20 @@
{% endif %} -

Nächste Schichten pro Raum

+{% if next_shifts %} +

Nächste Schichten

{% for shift in next_shifts %} + {% include "partials/shift_list_item.html" %} +{% endfor %} +
+{% endif %} +

Nächste Schichten pro Raum

+
+{% for shift in next_shifts_per_room %}
{{ shift.room.name }}
- + {% include "partials/shift_box.html" %}
diff --git a/shiftregister/team/urls.py b/shiftregister/team/urls.py index f8a4296..c76bf56 100644 --- a/shiftregister/team/urls.py +++ b/shiftregister/team/urls.py @@ -4,7 +4,7 @@ from . import views app_name = "team" urlpatterns = [ - path("", views.shift_overview, name="index"), + path("", views.index, name="index"), path("overview/", views.shift_overview, name="shift_overview"), path("shifts/", views.ShiftList.as_view(), name="shift_all"), path("room_shifts/", views.RoomShiftList.as_view(), name="shift_room"), diff --git a/shiftregister/team/views.py b/shiftregister/team/views.py index 7a26a05..f119157 100644 --- a/shiftregister/team/views.py +++ b/shiftregister/team/views.py @@ -11,31 +11,61 @@ from django.contrib import messages from django.db import models from django.core.paginator import Paginator from .forms import BulkMessage, HelperShift, HelperMessage +from datetime import timedelta # Create your views here. + + def index(request): - pass + return redirect("team:shift_overview") @login_required def shift_overview(request): + checkin_count = Count( + Case( + When( + shiftregistration__state=ShiftRegistration.RegState.CHECKED_IN, then=1 + ), + output_field=models.IntegerField(), + ) + ) + context = {} - context["running_shifts"] = [ - shift - for shift in Shift.with_reg_count() + context["running_shifts"] = ( + Shift.with_reg_count() .annotate( + checkin_count=Count( + Case( + When( + shiftregistration__state=ShiftRegistration.RegState.CHECKED_IN, + then=1, + ), + output_field=models.IntegerField(), + ) + ), end_at=ExpressionWrapper( - F("start_at") + F("duration"), - output_field=DateTimeField(), - ) + F("start_at") + F("duration"), output_field=DateTimeField() + ), ) .filter(start_at__lte=timezone.now(), end_at__gte=timezone.now(), deleted=False) .order_by("start_at") - ] + ) + + context["next_shifts"] = ( + Shift.with_reg_count() + .annotate(checkin_count=checkin_count) + .filter( + start_at__gt=timezone.now(), + start_at__lte=timezone.now() + timedelta(minutes=30), + deleted=False, + ) + .order_by("start_at") + ) # only Postgres supports DISTINCT on specific columns, SQLite does not support aggregates on datetime fields - context["next_shifts"] = filter( + context["next_shifts_per_room"] = filter( lambda x: x is not None, ( Shift.with_reg_count()