feat(submissions): scoped submissions per user/matchs, sync from polylan
This commit is contained in:
@@ -1,22 +1,79 @@
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from uuid import UUID
|
||||
from django.http import HttpRequest, Http404
|
||||
from django.shortcuts import redirect, render, get_object_or_404
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from events.models import Event
|
||||
from games.models import Game
|
||||
from .models import Scope
|
||||
|
||||
|
||||
@login_required
|
||||
def submission_home(request: HttpRequest, event_path: str, game: str):
|
||||
def submission_home(request: HttpRequest, event_path: str, game_path: str):
|
||||
event = get_object_or_404(Event, path=event_path)
|
||||
game_obj = get_object_or_404(
|
||||
Game.objects.enabled_for_event(event), path=f"/submissions/{game}"
|
||||
game = get_object_or_404(Game, path=game_path)
|
||||
|
||||
scopes = (
|
||||
Scope.objects.filter(event_game__event=event, event_game__game=game)
|
||||
if request.user.is_superuser
|
||||
else Scope.objects.filter(
|
||||
event_game__event=event,
|
||||
event_game__game=game,
|
||||
assigned_users=request.user,
|
||||
)
|
||||
)
|
||||
|
||||
if scopes.count() == 1:
|
||||
return redirect(
|
||||
"submissions.view",
|
||||
event_path=event.path,
|
||||
game_path=game.path,
|
||||
scope_id=scopes[0].id,
|
||||
)
|
||||
|
||||
if not scopes:
|
||||
raise Http404
|
||||
|
||||
return render(
|
||||
request,
|
||||
"submissions_select.html",
|
||||
{
|
||||
"event": event,
|
||||
"game": game,
|
||||
"scopes_data": [
|
||||
{"id": str(scope.id), "name": scope.name}
|
||||
for scope in scopes.order_by("name")
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def submission_view(
|
||||
request: HttpRequest, event_path: str, game_path: str, scope_id: UUID
|
||||
):
|
||||
event = get_object_or_404(Event, path=event_path)
|
||||
scope = get_object_or_404(
|
||||
Scope.objects.select_related("event_game__game").prefetch_related(
|
||||
"assigned_users"
|
||||
),
|
||||
id=scope_id,
|
||||
event_game__game__path=game_path,
|
||||
event_game__event=event,
|
||||
)
|
||||
|
||||
if (
|
||||
not request.user.is_superuser
|
||||
and not scope.assigned_users.filter(pk=request.user.pk).exists()
|
||||
):
|
||||
raise Http404
|
||||
|
||||
return render(
|
||||
request,
|
||||
"submissions.html",
|
||||
{
|
||||
"event": event,
|
||||
"game": game_obj,
|
||||
"scope": scope,
|
||||
"game": scope.event_game.game,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user