LMS / Course System: - Course → Module → Lesson hierarchy (any user can create) - Lesson types: text, video (Vimeo/YouTube/local), document, quiz, live_session - Video provider auto-detection from URL - BBB API integration (create/join meetings) with env config - Course enrollment with per-lesson progress tracking - AI content generation/refinement for text lessons - Draft/published/archived status workflow - Subscription gate placeholder (requires_subscription flag) - Thumbnail upload support - Module/lesson reorder with up/down controls User Quiz Creation: - Any user can create quizzes from question bank (was moderator-only) - User quizzes: is_published=0, is_shared=0 (private by default) - Fixed section_id fallback: None instead of hardcoded 1 Manual Question Creation: - POST /questions/create endpoint for manual MCQ entry - CreateQuestionModal on QuestionBankPage with options, radio for correct answer - Auto-generates embedding on creation Frontend: - CoursesPage: Browse/My Courses/Created tabs with search and pagination - CourseDetailPage: Student view with module accordion, lesson viewer, progress - CourseEditorPage: Full course builder with AI generate, question bank browser - Courses link in Navbar - Create Question button on Question Bank (available to all users) Backend: - 5 new tables: courses, course_modules, course_lessons, course_enrollments, course_lesson_progress - Course model + schemas + router (22 endpoints) - BBB_SERVER_URL + BBB_SECRET config - Updated CLAUDE.md with LMS documentation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
40 lines
2.1 KiB
Python
40 lines
2.1 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.database import Base
|
|
from app.models.quiz_category import QuizCategory # noqa — ensures mapper resolves "QuizCategory"
|
|
from app.models.quiz_question_link import QuizQuestionLink # noqa
|
|
|
|
|
|
class Quiz(Base):
|
|
__tablename__ = "quizzes"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
section_id = Column(Integer, ForeignKey("sections.id", ondelete="SET NULL"), nullable=True)
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
category_id = Column(Integer, ForeignKey("quiz_categories.id", ondelete="SET NULL"), nullable=True)
|
|
title = Column(String, nullable=False)
|
|
questions_count = Column(Integer, default=0)
|
|
time_limit_minutes = Column(Integer, nullable=True) # null = no limit
|
|
mode = Column(String, default="timed") # timed, learning
|
|
skipped_questions = Column(Text, nullable=True) # JSON list of skipped question texts
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
deleted_at = Column(DateTime, nullable=True) # soft delete — null = active
|
|
is_published = Column(Integer, default=1) # 1 = visible to users, 0 = hidden (admin only)
|
|
is_shared = Column(Integer, default=0) # 0=private, 1=shared (visible to other users)
|
|
|
|
section = relationship("Section", back_populates="quizzes")
|
|
user = relationship("User", back_populates="quizzes")
|
|
category = relationship("QuizCategory", back_populates="quizzes", foreign_keys=[category_id])
|
|
questions = relationship(
|
|
"Question",
|
|
secondary="quiz_question_links",
|
|
primaryjoin="Quiz.id == foreign(QuizQuestionLink.quiz_id)",
|
|
secondaryjoin="Question.id == foreign(QuizQuestionLink.question_id)",
|
|
order_by="QuizQuestionLink.position",
|
|
viewonly=True, # mutations handled explicitly via QuizQuestionLink
|
|
)
|
|
attempts = relationship("QuizAttempt", back_populates="quiz", cascade="all, delete-orphan")
|
|
reminders = relationship("ReminderSchedule", cascade="all, delete-orphan", foreign_keys="ReminderSchedule.quiz_id")
|