feat: Ausblenden vergangener Termine im Dashboard
This commit is contained in:
parent
4b350ff5c6
commit
9b2d00106f
Binary file not shown.
@ -2,7 +2,9 @@ from django.shortcuts import render
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from calendars.models import Event, EventParticipation
|
from calendars.models import Event, EventParticipation
|
||||||
from clubs.models import Team
|
from clubs.models import Team
|
||||||
|
from django.db.models import Q
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
import datetime
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard(request):
|
def dashboard(request):
|
||||||
@ -19,10 +21,15 @@ def dashboard(request):
|
|||||||
from itertools import chain
|
from itertools import chain
|
||||||
all_teams = list(set(chain(player_teams, coached_teams, assisted_teams)))
|
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:
|
if all_teams:
|
||||||
user_events = Event.objects.filter(team__in=all_teams)
|
user_events = Event.objects.filter(team__in=all_teams)
|
||||||
opened_games = Event.objects.filter(game__opened_for_teams__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:
|
for event in events:
|
||||||
participations = event.eventparticipation_set.all()
|
participations = event.eventparticipation_set.all()
|
||||||
@ -64,7 +71,9 @@ def dashboard(request):
|
|||||||
if child.team:
|
if child.team:
|
||||||
child_user_events = Event.objects.filter(team=child.team)
|
child_user_events = Event.objects.filter(team=child.team)
|
||||||
child_opened_games = Event.objects.filter(game__opened_for_teams=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:
|
for event in child_events:
|
||||||
participation, created = EventParticipation.objects.get_or_create(user=child, event=event)
|
participation, created = EventParticipation.objects.get_or_create(user=child, event=event)
|
||||||
|
|||||||
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user