From 4380f47302a05c49142bd00e4ba4fc856c269e78 Mon Sep 17 00:00:00 2001 From: Luca Date: Tue, 20 May 2025 01:57:03 +0200 Subject: [PATCH] feat: show previous and current day of week for shifts between 0 and 6 --- .../app/templates/partials/shift_listitem.html | 2 +- shiftregister/app/templates/shift.html | 2 +- shiftregister/app/templatetags/shift_extras.py | 18 ++++++++++++++++++ .../fallback/templates/my_fallback_shifts.html | 9 ++++++++- .../team/templates/partials/shift_box.html | 4 +++- .../team/templates/room_registrations.html | 4 +++- shiftregister/team/templates/shift_detail.html | 7 +++++++ 7 files changed, 41 insertions(+), 5 deletions(-) diff --git a/shiftregister/app/templates/partials/shift_listitem.html b/shiftregister/app/templates/partials/shift_listitem.html index 2cc710f..c6d6320 100644 --- a/shiftregister/app/templates/partials/shift_listitem.html +++ b/shiftregister/app/templates/partials/shift_listitem.html @@ -7,7 +7,7 @@ gelöscht
{% endif %} Ort: {{ shift.room.name }}
- Beginn: {{ shift.start_at }}
+ Beginn: {{ shift.start_at }}{% with shift.start_at|night_from_to as night %}{% if night %} ({{ night }}){% endif %}{% endwith %}
Dauer: {{ shift.duration|duration }}
Belegung: {{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }} diff --git a/shiftregister/app/templates/shift.html b/shiftregister/app/templates/shift.html index af2214b..898a33f 100644 --- a/shiftregister/app/templates/shift.html +++ b/shiftregister/app/templates/shift.html @@ -24,7 +24,7 @@

Ort: {{ shift.room.name }} 📍
- Beginn: {{ shift.start_at }}
+ Beginn: {{ shift.start_at }}{% with shift.start_at|night_from_to as night %}{% if night %} ({{ night }}){% endif %}{% endwith %}
Dauer: {{ shift.duration|duration }}
Treffpunkt: {{ shift.room.meeting_location|linebreaksbr }}
Belegung: {{ shift.registration_count }}/{{ shift.required_helpers|default:shift.room.required_helpers }} diff --git a/shiftregister/app/templatetags/shift_extras.py b/shiftregister/app/templatetags/shift_extras.py index 1f34c79..46d16d4 100644 --- a/shiftregister/app/templatetags/shift_extras.py +++ b/shiftregister/app/templatetags/shift_extras.py @@ -1,4 +1,7 @@ +from datetime import datetime, timedelta + from django import template +from django.utils import timezone register = template.Library() @@ -11,3 +14,18 @@ def duration(value): secs = secs % (hours * 60 * 60) minutes = secs // 60 return f"{hours}:{minutes:02d}h" + + +@register.filter(name="night_from_to") +def night_from_to(value): + if not isinstance(value, datetime): + raise ValueError("value must be a datetime object") + + value = value.astimezone(timezone.get_current_timezone()) + + if value.hour < 6: + date = value.date() + days = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"] + return f"{days[(date-timedelta(days=1)).weekday()]}\u2192{days[date.weekday()]}" + + return "" diff --git a/shiftregister/fallback/templates/my_fallback_shifts.html b/shiftregister/fallback/templates/my_fallback_shifts.html index 53ddc0e..915dff4 100644 --- a/shiftregister/fallback/templates/my_fallback_shifts.html +++ b/shiftregister/fallback/templates/my_fallback_shifts.html @@ -70,7 +70,14 @@ Diese Schichtzuteilung wurde maschinell erstellt und ist auch ohne Unterschrift {% with assignment.shift as shift %} {{ assignment.id }} {% if assignment.traded_to %}*{% endif %} - {{ shift.start_at }} + + {{ shift.start_at }} +{% with shift.start_at|night_from_to as night %} +{% if night %} + ({{ night }}) +{% endif %} +{% endwith %} + {{ shift.duration|duration }} {{ shift.room.name }} diff --git a/shiftregister/team/templates/partials/shift_box.html b/shiftregister/team/templates/partials/shift_box.html index 9256688..5624637 100644 --- a/shiftregister/team/templates/partials/shift_box.html +++ b/shiftregister/team/templates/partials/shift_box.html @@ -1,3 +1,5 @@ +{% load shift_extras %} +

@@ -5,7 +7,7 @@ gelöscht
{% endif %} Ort: {{ shift.room.name }}
- Beginn: {{ shift.start_at }}
+ Beginn: {{ shift.start_at }}{% with shift.start_at|night_from_to as night %}{% if night %} ({{ night }}){% endif %}{% endwith %}
Dauer: {{ shift.duration }}
{% if shift.event.calendar.restricted %} Nur Team: {{ shift.required_helpers|default:shift.room.required_helpers }} diff --git a/shiftregister/team/templates/room_registrations.html b/shiftregister/team/templates/room_registrations.html index 735a047..ca8a1ca 100644 --- a/shiftregister/team/templates/room_registrations.html +++ b/shiftregister/team/templates/room_registrations.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% load shift_extras %} + {% block title %}{{ room.name }}{% endblock %} {% block everything %} @@ -16,7 +18,7 @@ {% for shift in shifts %} - {{ shift.start_at }} + {{ shift.start_at }}{% with shift.start_at|night_from_to as night %}{% if night %} ({{ night }}){% endif %}{% endwith %} {% for reg in shift.valid_registrations.all %}{{ reg.helper.name }}{% if not forloop.last %}, {% endif %}{% endfor %} {% endfor %} diff --git a/shiftregister/team/templates/shift_detail.html b/shiftregister/team/templates/shift_detail.html index 306dbfc..abca0f9 100644 --- a/shiftregister/team/templates/shift_detail.html +++ b/shiftregister/team/templates/shift_detail.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% load shift_extras %} + {% block title %}Schichtdetails{% endblock %} {% block content %} @@ -7,6 +9,11 @@ {% if shift.deleted %}(gelöscht) {% endif %}
{{ shift.room.name }} {{ shift.start_at }} +{% with shift.start_at|night_from_to as night %} +{% if night %} + ({{ night }}) +{% endif %} +{% endwith %} {% if shift.event.calendar.restricted %} ({{ shift.required_helpers|default:shift.room.required_helpers }} Teamis) {% else %}