tournament outputs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from ninja import Router, File
|
||||
from ninja.files import UploadedFile
|
||||
from ninja.pagination import paginate
|
||||
from ninja.errors import HttpError
|
||||
from django.db import transaction
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.cache import cache
|
||||
@@ -10,13 +11,20 @@ from typing import List
|
||||
|
||||
from submissions.utils import verify_and_validate_ocr_date_for_submission
|
||||
|
||||
from .models import Submission, PuzzleResponse, SubmissionFile, SteamCollectionItem
|
||||
from .models import (
|
||||
Submission,
|
||||
PuzzleResponse,
|
||||
SubmissionFile,
|
||||
SteamCollectionItem,
|
||||
SteamCollection,
|
||||
)
|
||||
from .schemas import (
|
||||
SubmissionIn,
|
||||
SubmissionOut,
|
||||
PuzzleResponseOut,
|
||||
ValidationIn,
|
||||
SteamCollectionItemOut,
|
||||
SteamCollectionOut,
|
||||
)
|
||||
|
||||
router = Router()
|
||||
@@ -30,6 +38,13 @@ def list_puzzles(request):
|
||||
)
|
||||
|
||||
|
||||
@router.get("/collection", response=SteamCollectionOut)
|
||||
def get_collection(request):
|
||||
"""Get the active collection details"""
|
||||
collection = get_object_or_404(SteamCollection, is_active=True)
|
||||
return collection
|
||||
|
||||
|
||||
@router.get("/submissions", response=List[SubmissionOut])
|
||||
@paginate
|
||||
def list_submissions(request):
|
||||
@@ -65,7 +80,15 @@ def create_submission(
|
||||
if len(files) < len(data.responses):
|
||||
return 400, {"detail": "Not enough files for all responses"}
|
||||
|
||||
print(data, files)
|
||||
# Check if collection is accepting submissions
|
||||
if data.responses:
|
||||
for puzzle in data.responses:
|
||||
if not get_object_or_404(
|
||||
SteamCollectionItem, id=puzzle.puzzle_id
|
||||
).collection.accepting_submissions:
|
||||
raise HttpError(
|
||||
403, "This tournament is no longer accepting submissions"
|
||||
)
|
||||
|
||||
try:
|
||||
with transaction.atomic():
|
||||
@@ -126,7 +149,6 @@ def create_submission(
|
||||
# Process files for this response
|
||||
# For simplicity, we'll take one file per response
|
||||
# In a real implementation, you'd need better file-to-response mapping
|
||||
print("FI", file_index, files)
|
||||
if file_index < len(files):
|
||||
uploaded_file = files[file_index]
|
||||
|
||||
@@ -172,7 +194,6 @@ def create_submission(
|
||||
return submission
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return 500, {"detail": f"Error creating submission: {str(e)}"}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user