pdf-quiz-generator/backend/app/schemas/quiz.py
Daniel 9af63e67b5 Major: categories, question bank, security fixes, mobile layout, UX improvements
Security:
- Nginx: X-Frame-Options, X-Content-Type-Options, X-XSS-Protection, CSP, Referrer-Policy, Permissions-Policy headers
- Redis-backed login rate limiting (survives container restarts)
- Admin litellm/models endpoint: api_key moved from GET query param to POST body
- Nextcloud credentials moved from localStorage to sessionStorage (cleared on tab close)

UX / Layout:
- Login: unverified users see inline "Resend verification email" option
- QuizPage mobile: TTS Listen button on its own row below question text
- QuizPage mobile: Voice selector on its own row in header card (not squashed with timer)
- QuizEditPage: scroll position preserved after saving a question edit

Quiz Categories:
- New QuizCategory model + quiz_categories table
- category_id column added to quizzes table
- GET/POST/DELETE /api/categories endpoints
- Quizzes grouped by category in QuizzesPage; moderators can assign via 🏷 menu
- Uncategorized section shown when categories exist

Question Bank:
- GET /api/questions/bank — search all questions across quizzes
- POST /api/questions/from-bank — create new quiz from selected questions (copies, originals untouched)
- QuestionBankPage: search, checkbox select, study modal, create quiz form
- "Question Bank" link added to Navbar

Search:
- "View all N questions →" button expands to full question list
- Each question has a Study button opening in-place modal with study mode
- Summary view shows 2 questions per quiz with Study button

Extraction prompt:
- Stronger emphasis on correct_answer field with step-by-step letter → full text example
- Explicit instruction never to store just the letter

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 20:08:05 +02:00

57 lines
1.2 KiB
Python

from datetime import datetime
from pydantic import BaseModel
class QuizCreate(BaseModel):
section_id: int
title: str
mode: str = "timed" # timed, learning
time_limit_minutes: int | None = None
model_id: str | None = None # override extraction model
class QuestionResponse(BaseModel):
id: int
question_text: str
question_type: str
options: list[str] | None
image_path: str | None = None
class Config:
from_attributes = True
class QuestionWithAnswer(QuestionResponse):
correct_answer: str
explanation: str | None
page_reference: int | None
class QuizResponse(BaseModel):
id: int
section_id: int
user_id: int
title: str
questions_count: int
mode: str
time_limit_minutes: int | None
skipped_questions: str | None = None
category_id: int | None = None
created_at: datetime
class Config:
from_attributes = True
class QuizDetail(QuizResponse):
questions: list[QuestionResponse] = []
class QuizLearningDetail(QuizResponse):
"""Learning mode — includes answers and explanations."""
questions: list[QuestionWithAnswer] = []
class QuizReview(QuizResponse):
questions: list[QuestionWithAnswer] = []