2
0
Fork 0

Fix team dashboard

This commit is contained in:
Luca 2023-05-19 03:36:59 +02:00
parent 175ce50ccb
commit d18b2d6d3d
3 changed files with 23 additions and 6 deletions

View File

@ -19,6 +19,10 @@
<td>{{ shift.start_at }}</td>
<td>{% for fa in shift.fallbackassignment_set.all %}{{ fa.team_member.name }}{% if not forloop.last %}, {% endif %}{% endfor %}</td>
</tr>
{% empty %}
<tr>
<td colspan="3">:)</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -1,5 +1,6 @@
from datetime import timedelta
from django.db.models import Case, Count, F, Q, Sum, When
from django.db import models
from django.db.models import Case, Count, F, ExpressionWrapper, Q, Sum, When
from django.shortcuts import render
from django.utils import timezone
from .models import Helper, Shift, ShiftRegistration
@ -47,11 +48,24 @@ def public_dashboard(request):
def team_dashboard(request):
today = timezone.now().date()
now = timezone.localtime()
changeover = now.replace(hour=6, minute=0, second=0, microsecond=0)
today = now.date()
if now.hour < changeover.hour:
day_end = changeover
day_start = day_end - timedelta(days=1)
today = today - timedelta(days=1)
else:
day_start = changeover
day_end = day_start + timedelta(days=1)
team_shifts = (
Shift.with_reg_count()
.annotate(
end_at=ExpressionWrapper(
F("start_at") + F("duration"), output_field=models.DateTimeField()
),
real_required_helpers=Case(
When(required_helpers=0, then=F("room__required_helpers")),
default=F("required_helpers"),
@ -60,9 +74,9 @@ def team_dashboard(request):
)
.filter(
deleted=False,
start_at__gt=today + timedelta(hours=6),
start_at__lte=today + timedelta(hours=30),
start_at__gte=timezone.now(),
start_at__gte=day_start,
start_at__lt=day_end,
end_at__gt=now,
reg_count__lt=F("real_required_helpers"),
fallbackassignment_count__gt=0,
)

View File

@ -6,7 +6,6 @@ import shiftregister.team.models
class Migration(migrations.Migration):
dependencies = [
("app", "0011_room_description"),
("team", "0003_incomingmessage_read_and_more"),