Files
polylan-submitter/polylan_submitter/submissions/management/commands/sync_scopes.py
T

48 lines
1.6 KiB
Python

from django.core.management.base import BaseCommand, CommandError
from games.models import EventGame
from submissions.tasks import sync_all_event_games_task, sync_event_game_scopes_task
class Command(BaseCommand):
help = "Queue a sync of Scopes (matches) and their assigned users from the legacy AAndT API."
def add_arguments(self, parser):
parser.add_argument(
"--event-game",
type=int,
default=None,
help=(
"Only queue a sync for the EventGame with this id. "
"Default: every EventGame with an AAndT token configured."
),
)
def handle(self, *args, **options):
event_game_id = options["event_game"]
if event_game_id is not None:
if not EventGame.objects.filter(id=event_game_id).exists():
raise CommandError(f"No EventGame with id={event_game_id}")
sync_event_game_scopes_task.enqueue(event_game_id)
self.stdout.write(
self.style.SUCCESS(f"Queued sync for EventGame {event_game_id}")
)
return
if (
not EventGame.objects.exclude(apibot_token__isnull=True)
.exclude(apibot_token="")
.exists()
):
self.stdout.write(
self.style.WARNING("No EventGame has an AAndT token configured.")
)
return
sync_all_event_games_task.enqueue()
self.stdout.write(
self.style.SUCCESS("Queued sync for every EventGame with an AAndT token.")
)