add custom filter to format shift durations

pull/1/head
parent 8a8c415015
commit 3957c659e6

@ -1,3 +1,4 @@
{% load shift_extras %}
<div class="column is-one-quarter">
<div class="box">
<div class="content">
@ -6,7 +7,7 @@
{% endif %}
<strong>Ort:</strong> {{ shift.room.name }}<br>
<strong>Beginn:</strong> {{ shift.start_at }}<br>
<strong>Dauer:</strong> {{ shift.duration }}
<strong>Dauer:</strong> {{ shift.duration|duration }}
</div>
<div class="buttons is-right">
<a class="button is-info is-small mr-0" href="{% url 'shift' shift.id %}">Details</a>

@ -1,4 +1,5 @@
{% extends "helper_base.html" %}
{% load shift_extras %}
{% block title %}Schichtansicht{% endblock %}
@ -17,7 +18,7 @@
<p>
<strong>Ort:</strong> <a href="{% url 'pages:view' 'map' %}#{{ shift.room.name|slugify }}">{{ shift.room.name }} 📍</a><br>
<strong>Beginn:</strong> {{ shift.start_at }}<br>
<strong>Dauer:</strong> {{ shift.duration }}<br>
<strong>Dauer:</strong> {{ shift.duration|duration }}<br>
<strong>Treffpunkt:</strong> {{ shift.room.meeting_location|linebreaksbr }}
</p>
{% if shift.room.description %}

@ -0,0 +1,12 @@
from django import template
register = template.Library()
@register.filter(name="duration")
def duration(value):
secs = value.total_seconds()
hours = int(secs // (60 * 60))
secs = secs % (hours * 60 * 60)
minutes = int(secs // 60)
return f"{hours}:{minutes:02d}"
Loading…
Cancel
Save