feat: Ausblenden vergangener Termine im Dashboard

This commit is contained in:
Matthias Nagel 2025-10-02 21:42:46 +02:00
parent 4b350ff5c6
commit 9b2d00106f
3 changed files with 11 additions and 2 deletions

View File

@ -2,7 +2,9 @@ from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from calendars.models import Event, EventParticipation
from clubs.models import Team
from django.db.models import Q
from django.utils import timezone
import datetime
@login_required
def dashboard(request):
@ -19,10 +21,15 @@ def dashboard(request):
from itertools import chain
all_teams = list(set(chain(player_teams, coached_teams, assisted_teams)))
now = timezone.now()
three_hours_ago = now - datetime.timedelta(hours=3)
if all_teams:
user_events = Event.objects.filter(team__in=all_teams)
opened_games = Event.objects.filter(game__opened_for_teams__in=all_teams)
events = (user_events | opened_games).distinct().select_related('game', 'training').prefetch_related('team__players', 'eventparticipation_set__user', 'game__opened_for_teams').order_by('start_time')
events = (user_events | opened_games).distinct().filter(
Q(end_time__gte=three_hours_ago) | Q(end_time__isnull=True, start_time__gte=three_hours_ago)
).select_related('game', 'training').prefetch_related('team__players', 'eventparticipation_set__user', 'game__opened_for_teams').order_by('start_time')
for event in events:
participations = event.eventparticipation_set.all()
@ -64,7 +71,9 @@ def dashboard(request):
if child.team:
child_user_events = Event.objects.filter(team=child.team)
child_opened_games = Event.objects.filter(game__opened_for_teams=child.team)
child_events = (child_user_events | child_opened_games).distinct().select_related('game', 'training').order_by('start_time')
child_events = (child_user_events | child_opened_games).distinct().filter(
Q(end_time__gte=three_hours_ago) | Q(end_time__isnull=True, start_time__gte=three_hours_ago)
).select_related('game', 'training').order_by('start_time')
for event in child_events:
participation, created = EventParticipation.objects.get_or_create(user=child, event=event)

Binary file not shown.