Add Orthobullets-inspired numbered-answer UI, explicit study response confirmation, response statistics, review navigation, safe calculator, keyboard controls and sourced educator lab references. Persist attempt mode to prevent query-flag exam disclosure. Combined deployed-image backend suite (22), frontend suite (48), build and synthetic desktop/mobile browser checks pass. PostgreSQL round-trip and independent review remain release gates; no production deployment.
38 lines
1.7 KiB
Python
38 lines
1.7 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)
|
|
mode = Column(String(10), nullable=True) # legacy NULL resumes without exposing answers
|
|
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
|
|
expired = Column(Integer, default=0) # 1 = auto-submitted due to timer expiry (abandoned), excluded from history
|
|
|
|
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")
|