- Fully decouple course quizzes from main quiz system (hidden from dashboard stats, history, search, results page) - Course quiz results show "Back to Course" instead of retake/delete - Add allow_review toggle for course creators to control answer review - Show quiz title on course page, hide pool size from students - Add course thumbnails to browse cards - Replace passlib with bcrypt directly (compatible with existing hashes) - Add HIBP breached password warnings on register/reset/change password - Add CLI management tools (reset-password, set-role, stats, etc.) - Fix quiz PATCH endpoint: ownership check instead of moderator-only - Add max_length validation on course/module/lesson titles - Fix score display bug on results page (0 of N when review disabled) - Fix question count on course quiz start (show per-attempt, not pool) - Improve suspend warning for timed course quizzes with max attempts - Clean up validation error messages (show "Invalid email" not Pydantic dump) - Add DDL migration for allow_review column Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, Integer, Boolean, String, DateTime, ForeignKey, JSON
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class QuizAttempt(Base):
|
|
__tablename__ = "quiz_attempts"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
quiz_id = Column(Integer, ForeignKey("quizzes.id", ondelete="CASCADE"), nullable=False)
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
score = Column(Integer, default=0)
|
|
total_questions = Column(Integer, default=0)
|
|
started_at = Column(DateTime, default=datetime.utcnow)
|
|
completed_at = Column(DateTime, nullable=True)
|
|
selected_question_ids = Column(JSON, nullable=True) # for question pool: which questions this attempt uses
|
|
|
|
quiz = relationship("Quiz", back_populates="attempts")
|
|
user = relationship("User", back_populates="attempts")
|
|
answers = relationship("AttemptAnswer", back_populates="attempt", cascade="all, delete-orphan")
|
|
|
|
|
|
class AttemptAnswer(Base):
|
|
__tablename__ = "attempt_answers"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
attempt_id = Column(Integer, ForeignKey("quiz_attempts.id", ondelete="CASCADE"), nullable=False)
|
|
question_id = Column(Integer, ForeignKey("questions.id", ondelete="CASCADE"), nullable=False)
|
|
user_answer = Column(String, nullable=False)
|
|
is_correct = Column(Boolean, default=False)
|
|
|
|
attempt = relationship("QuizAttempt", back_populates="answers")
|
|
question = relationship("Question")
|