From 5bb4db1b1df26dca435044e0b2b3aa2d230f7a62 Mon Sep 17 00:00:00 2001 From: Jonathan Samuel Date: Wed, 4 Sep 2024 22:25:22 +0530 Subject: [PATCH 1/2] regs: Backfill older regs with teams linked to players --- ...kfill_team_to_player_from_registrations.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 server/migrations/0091_backfill_team_to_player_from_registrations.py diff --git a/server/migrations/0091_backfill_team_to_player_from_registrations.py b/server/migrations/0091_backfill_team_to_player_from_registrations.py new file mode 100644 index 00000000..67fc2c38 --- /dev/null +++ b/server/migrations/0091_backfill_team_to_player_from_registrations.py @@ -0,0 +1,29 @@ +from django.db import migrations +from django.db.backends.base.schema import BaseDatabaseSchemaEditor +from django.db.migrations.state import StateApps + + +def add_team_to_player_from_registrations( + apps: StateApps, schema_editor: BaseDatabaseSchemaEditor +) -> None: + SeriesRegistration = apps.get_model("server", "SeriesRegistration") # noqa: N806 + series_registrations = SeriesRegistration.objects.all() + + Registration = apps.get_model("server", "Registration") # noqa: N806 + registrations = Registration.objects.all() + + for series_registration in series_registrations: + series_registration.player.teams.add(series_registration.team) + + for registration in registrations: + registration.player.teams.add(registration.team) + + +class Migration(migrations.Migration): + dependencies = [("server", "0090_alter_player_teams")] + + operations = [ + migrations.RunPython( + code=add_team_to_player_from_registrations, reverse_code=migrations.RunPython.noop + ) + ] From b60bfe28d4cfc47c80618ae3407ed74fd8b9b1c2 Mon Sep 17 00:00:00 2001 From: Jonathan Samuel Date: Wed, 4 Sep 2024 22:39:28 +0530 Subject: [PATCH 2/2] regs: Update player teams on day of tournament --- .../open_or_close_tournament_registrations.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/server/management/commands/open_or_close_tournament_registrations.py b/server/management/commands/open_or_close_tournament_registrations.py index 68fe3cc6..67f25c82 100644 --- a/server/management/commands/open_or_close_tournament_registrations.py +++ b/server/management/commands/open_or_close_tournament_registrations.py @@ -3,13 +3,11 @@ from django.core.management.base import BaseCommand from django.utils.timezone import now -from server.tournament.models import Tournament +from server.tournament.models import Registration, Tournament class Command(BaseCommand): - help = ( - "Check if registrations are open or closed today, and update tournament status accordingly" - ) + help = "Check if registrations are open or closed today, and update tournament status accordingly. Also update registration's player teams on day of tournament" def handle(self, *args: Any, **options: Any) -> None: today = now().date() @@ -26,3 +24,13 @@ def handle(self, *args: Any, **options: Any) -> None: if team_registrations_closed_today.count() > 0: team_registrations_closed_today.update(status=Tournament.Status.SCHEDULING) + + tournaments_that_starts_today = Tournament.objects.filter( + event__start_date__exact=today, status=Tournament.Status.LIVE + ) + + for tournament in tournaments_that_starts_today: + registrations = Registration.objects.filter(event=tournament.event) + + for reg in registrations: + reg.player.teams.add(reg.team)