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)."
)
)