fix dashboard

sync3
Razmig Sarkissian 5 months ago
parent 621639f30e
commit 621f37791c
  1. 42
      tournaments/admin.py

@ -94,33 +94,33 @@ class TournamentAdmin(SyncedObjectAdmin):
# Calculate date ranges # Calculate date ranges
now = timezone.now() now = timezone.now()
today = now.date() today = now.date()
week_ago = today - timedelta(days=7) week_start = today - timedelta(days=today.weekday()) # Monday of this week
month_ago = today - timedelta(days=30) week_end = week_start + timedelta(days=6) # Sunday of this week
month_start = today.replace(day=1) # First day of current month
# Tournament statistics - running today # Tournament statistics - tournaments starting TODAY
tournaments_today = Tournament.objects.filter( tournaments_today = Tournament.objects.filter(
start_date__date__lte=today, start_date__date=today
end_date__date__gte=today
).exclude(is_deleted=True) ).exclude(is_deleted=True)
tournaments_today_private = tournaments_today.filter(is_private=True).count() tournaments_today_private = tournaments_today.filter(is_private=True).count()
tournaments_today_public = tournaments_today.filter(is_private=False).count() tournaments_today_public = tournaments_today.filter(is_private=False).count()
tournaments_today_total = tournaments_today.count() tournaments_today_total = tournaments_today.count()
# Tournament statistics - running this week # Tournament statistics - tournaments starting THIS WEEK
tournaments_this_week = Tournament.objects.filter( tournaments_this_week = Tournament.objects.filter(
Q(start_date__date__gte=week_ago) | start_date__date__gte=week_start,
Q(end_date__date__gte=week_ago, start_date__date__lte=today) start_date__date__lte=week_end
).exclude(is_deleted=True) ).exclude(is_deleted=True)
tournaments_week_private = tournaments_this_week.filter(is_private=True).count() tournaments_week_private = tournaments_this_week.filter(is_private=True).count()
tournaments_week_public = tournaments_this_week.filter(is_private=False).count() tournaments_week_public = tournaments_this_week.filter(is_private=False).count()
tournaments_week_total = tournaments_this_week.count() tournaments_week_total = tournaments_this_week.count()
# Tournament statistics - running this month # Tournament statistics - tournaments starting THIS MONTH
tournaments_this_month = Tournament.objects.filter( tournaments_this_month = Tournament.objects.filter(
Q(start_date__date__gte=month_ago) | start_date__date__gte=month_start,
Q(end_date__date__gte=month_ago, start_date__date__lte=today) start_date__date__lte=today + timedelta(days=31 - today.day) # End of current month
).exclude(is_deleted=True) ).exclude(is_deleted=True)
tournaments_month_private = tournaments_this_month.filter(is_private=True).count() tournaments_month_private = tournaments_this_month.filter(is_private=True).count()
@ -133,23 +133,23 @@ class TournamentAdmin(SyncedObjectAdmin):
tournaments_all_public = all_tournaments.filter(is_private=False).count() tournaments_all_public = all_tournaments.filter(is_private=False).count()
tournaments_all_total = all_tournaments.count() tournaments_all_total = all_tournaments.count()
# Ended tournaments # Ended tournaments (tournaments that have an end_date in the past)
tournaments_ended_today = Tournament.objects.filter( tournaments_ended_today = Tournament.objects.filter(
end_date__date=today end_date__date=today
).exclude(is_deleted=True) ).exclude(is_deleted=True)
tournaments_ended_week = Tournament.objects.filter( tournaments_ended_week = Tournament.objects.filter(
end_date__date__gte=week_ago, end_date__date__gte=week_start,
end_date__date__lte=today end_date__date__lte=week_end
).exclude(is_deleted=True) ).exclude(is_deleted=True)
tournaments_ended_month = Tournament.objects.filter( tournaments_ended_month = Tournament.objects.filter(
end_date__date__gte=month_ago, end_date__date__gte=month_start,
end_date__date__lte=today end_date__date__lte=today + timedelta(days=31 - today.day)
).exclude(is_deleted=True) ).exclude(is_deleted=True)
tournaments_ended_all = Tournament.objects.filter( tournaments_ended_all = Tournament.objects.filter(
end_date__lt=now end_date__date__lt=today
).exclude(is_deleted=True) ).exclude(is_deleted=True)
# Team and player statistics # Team and player statistics
@ -184,17 +184,17 @@ class TournamentAdmin(SyncedObjectAdmin):
'app_label': 'tournaments', 'app_label': 'tournaments',
'opts': Tournament._meta, 'opts': Tournament._meta,
# Today statistics # Today statistics (tournaments STARTING today)
'tournaments_today_total': tournaments_today_total, 'tournaments_today_total': tournaments_today_total,
'tournaments_today_private': tournaments_today_private, 'tournaments_today_private': tournaments_today_private,
'tournaments_today_public': tournaments_today_public, 'tournaments_today_public': tournaments_today_public,
# Week statistics # Week statistics (tournaments STARTING this week)
'tournaments_week_total': tournaments_week_total, 'tournaments_week_total': tournaments_week_total,
'tournaments_week_private': tournaments_week_private, 'tournaments_week_private': tournaments_week_private,
'tournaments_week_public': tournaments_week_public, 'tournaments_week_public': tournaments_week_public,
# Month statistics # Month statistics (tournaments STARTING this month)
'tournaments_month_total': tournaments_month_total, 'tournaments_month_total': tournaments_month_total,
'tournaments_month_private': tournaments_month_private, 'tournaments_month_private': tournaments_month_private,
'tournaments_month_public': tournaments_month_public, 'tournaments_month_public': tournaments_month_public,
@ -204,7 +204,7 @@ class TournamentAdmin(SyncedObjectAdmin):
'tournaments_all_private': tournaments_all_private, 'tournaments_all_private': tournaments_all_private,
'tournaments_all_public': tournaments_all_public, 'tournaments_all_public': tournaments_all_public,
# Ended tournaments # Ended tournaments (tournaments ENDING in the respective periods)
'tournaments_ended_today': tournaments_ended_today.count(), 'tournaments_ended_today': tournaments_ended_today.count(),
'tournaments_ended_week': tournaments_ended_week.count(), 'tournaments_ended_week': tournaments_ended_week.count(),
'tournaments_ended_month': tournaments_ended_month.count(), 'tournaments_ended_month': tournaments_ended_month.count(),

Loading…
Cancel
Save