tournament outputs
This commit is contained in:
@@ -81,6 +81,7 @@ class SteamCollectionAdmin(admin.ModelAdmin):
|
||||
"current_favorites",
|
||||
"last_fetched",
|
||||
"is_active",
|
||||
"accepting_submissions",
|
||||
]
|
||||
list_filter = ["is_active", "last_fetched", "created_at"]
|
||||
search_fields = ["title", "steam_id", "author_name", "description"]
|
||||
@@ -115,7 +116,7 @@ class SteamCollectionAdmin(admin.ModelAdmin):
|
||||
)
|
||||
},
|
||||
),
|
||||
("Status", {"fields": ("fetch_error",)}),
|
||||
("Status", {"fields": ("fetch_error", "accepting_submissions")}),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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)}"}
|
||||
|
||||
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 5.2.7 on 2026-05-21 10:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("submissions", "0013_steamcollectionitem_points_value"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="steamcollection",
|
||||
name="accepting_submissions",
|
||||
field=models.BooleanField(
|
||||
default=True,
|
||||
help_text="Whether the tournament is accepting new submissions",
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -157,6 +157,9 @@ class SteamCollection(models.Model):
|
||||
is_active = models.BooleanField(
|
||||
default=True, help_text="Whether this collection is actively tracked"
|
||||
)
|
||||
accepting_submissions = models.BooleanField(
|
||||
default=True, help_text="Whether the tournament is accepting new submissions"
|
||||
)
|
||||
fetch_error = models.TextField(
|
||||
blank=True, help_text="Last error encountered when fetching data"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import List, Optional
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from .models import Submission, PuzzleResponse, SubmissionFile, SteamCollectionItem
|
||||
from .models import Submission, PuzzleResponse, SubmissionFile, SteamCollectionItem, SteamCollection
|
||||
|
||||
|
||||
# Input Schemas
|
||||
@@ -140,6 +140,26 @@ class PuzzlePointsFactorOut(Schema):
|
||||
area: int
|
||||
|
||||
|
||||
class SteamCollectionOut(ModelSchema):
|
||||
"""Schema for Steam collection output"""
|
||||
|
||||
class Meta:
|
||||
model = SteamCollection
|
||||
fields = [
|
||||
"id",
|
||||
"steam_id",
|
||||
"title",
|
||||
"description",
|
||||
"author_name",
|
||||
"total_items",
|
||||
"unique_visitors",
|
||||
"current_favorites",
|
||||
"accepting_submissions",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
|
||||
class SteamCollectionItemOut(ModelSchema):
|
||||
"""Schema for Steam collection item output"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user