user info + max size
This commit is contained in:
@@ -5,13 +5,13 @@ from django.db import transaction
|
||||
from django.core.files.base import ContentFile
|
||||
from django.http import Http404
|
||||
from django.utils import timezone
|
||||
from django.shortcuts import get_object_or_404
|
||||
from typing import List
|
||||
|
||||
from .models import Submission, PuzzleResponse, SubmissionFile, SteamCollectionItem
|
||||
from .schemas import (
|
||||
SubmissionIn,
|
||||
SubmissionOut,
|
||||
SubmissionListOut,
|
||||
PuzzleResponseOut,
|
||||
ValidationIn,
|
||||
SteamCollectionItemOut,
|
||||
@@ -26,23 +26,24 @@ def list_puzzles(request):
|
||||
return SteamCollectionItem.objects.select_related("collection").all()
|
||||
|
||||
|
||||
@router.get("/submissions", response=List[SubmissionListOut])
|
||||
@router.get("/submissions", response=List[SubmissionOut])
|
||||
@paginate
|
||||
def list_submissions(request):
|
||||
"""Get paginated list of submissions"""
|
||||
return Submission.objects.prefetch_related("responses").all()
|
||||
return Submission.objects.prefetch_related(
|
||||
"responses__files", "responses__puzzle"
|
||||
).filter(user=request.user)
|
||||
|
||||
|
||||
@router.get("/submissions/{submission_id}", response=SubmissionOut)
|
||||
def get_submission(request, submission_id: str):
|
||||
"""Get detailed submission by ID"""
|
||||
try:
|
||||
submission = Submission.objects.prefetch_related(
|
||||
return get_object_or_404(
|
||||
Submission.objects.prefetch_related(
|
||||
"responses__files", "responses__puzzle"
|
||||
).get(id=submission_id)
|
||||
return submission
|
||||
except Submission.DoesNotExist:
|
||||
raise Http404("Submission not found")
|
||||
).filter(user=request.user),
|
||||
id=submission_id,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/submissions", response=SubmissionOut)
|
||||
@@ -104,9 +105,9 @@ def create_submission(
|
||||
"detail": f"Invalid file type: {uploaded_file.content_type}"
|
||||
}
|
||||
|
||||
# Validate file size (10MB limit)
|
||||
if uploaded_file.size > 10 * 1024 * 1024:
|
||||
return 400, {"detail": "File too large (max 10MB)"}
|
||||
# Validate file size (256MB limit)
|
||||
if uploaded_file.size > 256 * 1024 * 1024:
|
||||
return 400, {"detail": "File too large (max 256MB)"}
|
||||
|
||||
# Create submission file
|
||||
submission_file = SubmissionFile.objects.create(
|
||||
|
||||
@@ -10,6 +10,7 @@ from .models import Submission, PuzzleResponse, SubmissionFile, SteamCollectionI
|
||||
# Input Schemas
|
||||
class SubmissionFileIn(Schema):
|
||||
"""Schema for file upload data"""
|
||||
|
||||
original_filename: str
|
||||
content_type: str
|
||||
ocr_data: Optional[dict] = None
|
||||
@@ -17,6 +18,7 @@ class SubmissionFileIn(Schema):
|
||||
|
||||
class PuzzleResponseIn(Schema):
|
||||
"""Schema for creating a puzzle response"""
|
||||
|
||||
puzzle_id: int
|
||||
puzzle_name: str
|
||||
cost: Optional[str] = None
|
||||
@@ -28,6 +30,7 @@ class PuzzleResponseIn(Schema):
|
||||
|
||||
class SubmissionIn(Schema):
|
||||
"""Schema for creating a submission"""
|
||||
|
||||
notes: Optional[str] = None
|
||||
responses: List[PuzzleResponseIn]
|
||||
|
||||
@@ -35,51 +38,76 @@ class SubmissionIn(Schema):
|
||||
# Output Schemas
|
||||
class SubmissionFileOut(ModelSchema):
|
||||
"""Schema for submission file output"""
|
||||
|
||||
file_url: Optional[str]
|
||||
|
||||
|
||||
class Meta:
|
||||
model = SubmissionFile
|
||||
fields = [
|
||||
'id', 'original_filename', 'file_size', 'content_type',
|
||||
'ocr_processed', 'ocr_raw_data', 'ocr_error', 'created_at'
|
||||
"id",
|
||||
"original_filename",
|
||||
"file_size",
|
||||
"content_type",
|
||||
"ocr_processed",
|
||||
"ocr_raw_data",
|
||||
"ocr_error",
|
||||
"created_at",
|
||||
]
|
||||
|
||||
|
||||
class PuzzleResponseOut(ModelSchema):
|
||||
"""Schema for puzzle response output"""
|
||||
|
||||
files: List[SubmissionFileOut]
|
||||
final_cost: Optional[str]
|
||||
final_cycles: Optional[str]
|
||||
final_area: Optional[str]
|
||||
|
||||
|
||||
class Meta:
|
||||
model = PuzzleResponse
|
||||
fields = [
|
||||
'id', 'puzzle', 'puzzle_name', 'cost', 'cycles', 'area',
|
||||
'needs_manual_validation', 'ocr_confidence_score',
|
||||
'validated_cost', 'validated_cycles', 'validated_area',
|
||||
'created_at', 'updated_at'
|
||||
"id",
|
||||
"puzzle",
|
||||
"puzzle_name",
|
||||
"cost",
|
||||
"cycles",
|
||||
"area",
|
||||
"needs_manual_validation",
|
||||
"ocr_confidence_score",
|
||||
"validated_cost",
|
||||
"validated_cycles",
|
||||
"validated_area",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
|
||||
class SubmissionOut(ModelSchema):
|
||||
"""Schema for submission output"""
|
||||
|
||||
responses: List[PuzzleResponseOut]
|
||||
total_responses: int
|
||||
needs_validation: bool
|
||||
|
||||
|
||||
class Meta:
|
||||
model = Submission
|
||||
fields = [
|
||||
'id', 'user', 'notes', 'is_validated', 'validated_by',
|
||||
'validated_at', 'created_at', 'updated_at'
|
||||
"id",
|
||||
"user",
|
||||
"notes",
|
||||
"is_validated",
|
||||
"validated_by",
|
||||
"validated_at",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
|
||||
class SubmissionListOut(Schema):
|
||||
"""Schema for submission list output"""
|
||||
|
||||
id: UUID
|
||||
user: Optional[int]
|
||||
# user: int
|
||||
notes: Optional[str]
|
||||
total_responses: int
|
||||
needs_validation: bool
|
||||
@@ -91,6 +119,7 @@ class SubmissionListOut(Schema):
|
||||
# Validation Schemas
|
||||
class ValidationIn(Schema):
|
||||
"""Schema for manual validation input"""
|
||||
|
||||
validated_cost: Optional[str] = None
|
||||
validated_cycles: Optional[str] = None
|
||||
validated_area: Optional[str] = None
|
||||
@@ -99,24 +128,49 @@ class ValidationIn(Schema):
|
||||
# Collection Schemas
|
||||
class SteamCollectionItemOut(ModelSchema):
|
||||
"""Schema for Steam collection item output"""
|
||||
|
||||
steam_url: str
|
||||
|
||||
|
||||
class Meta:
|
||||
model = SteamCollectionItem
|
||||
fields = [
|
||||
'id', 'steam_item_id', 'title', 'author_name', 'description',
|
||||
'tags', 'order_index', 'created_at', 'updated_at'
|
||||
"id",
|
||||
"steam_item_id",
|
||||
"title",
|
||||
"author_name",
|
||||
"description",
|
||||
"tags",
|
||||
"order_index",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
|
||||
# Error Schemas
|
||||
class ErrorOut(Schema):
|
||||
"""Schema for error responses"""
|
||||
|
||||
detail: str
|
||||
code: Optional[str] = None
|
||||
|
||||
|
||||
class ValidationErrorOut(Schema):
|
||||
"""Schema for validation error responses"""
|
||||
|
||||
detail: str
|
||||
errors: dict
|
||||
|
||||
|
||||
# User Schemas
|
||||
class UserInfoOut(Schema):
|
||||
"""Schema for user information output"""
|
||||
|
||||
id: Optional[int] = None
|
||||
username: Optional[str] = None
|
||||
first_name: Optional[str] = None
|
||||
last_name: Optional[str] = None
|
||||
email: Optional[str] = None
|
||||
is_authenticated: bool
|
||||
is_staff: bool
|
||||
is_superuser: bool
|
||||
cas_groups: Optional[List[str]] = None
|
||||
|
||||
Reference in New Issue
Block a user