feat(submissions): scoped submissions per user/matchs, sync from polylan

This commit is contained in:
2026-09-16 13:12:22 +02:00
parent 85e67599af
commit fabf06e6d4
35 changed files with 1008 additions and 92 deletions
@@ -0,0 +1,43 @@
from django.core.management.base import BaseCommand, CommandError
from accounts.models import CustomUser
from games.models import EventGame
from submissions.models import Scope
class Command(BaseCommand):
help = "Manually create a Scope (match) and assign users to it."
def add_arguments(self, parser):
parser.add_argument("event_game_id", type=int)
parser.add_argument("name", type=str)
parser.add_argument(
"--user",
dest="usernames",
action="append",
default=[],
help="Username to assign to this scope. Repeatable.",
)
def handle(self, *args, **options):
try:
event_game = EventGame.objects.get(id=options["event_game_id"])
except EventGame.DoesNotExist:
raise CommandError(f"No EventGame with id={options['event_game_id']}")
usernames = options["usernames"]
users = list(CustomUser.objects.filter(username__in=usernames))
missing = set(usernames) - {u.username for u in users}
if missing:
raise CommandError(f"Unknown usernames: {', '.join(sorted(missing))}")
scope = Scope.objects.create(event_game=event_game, name=options["name"])
scope.assigned_users.set(users)
self.stdout.write(
self.style.SUCCESS(
f"Created scope '{scope.name}' (id={scope.id}) "
f"with {len(users)} assigned user(s)."
)
)
@@ -0,0 +1,47 @@
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.")
)