Exemple #1
0
class Report(db.Model):
    __tablename__ = "reports"

    id = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, default=datetime.utcnow)
    event = db.Column(db.String)
    quiz_id = db.Column(db.Integer, db.ForeignKey("quizzes.id"))
    submission_id = db.Column(db.Integer, db.ForeignKey("submissions.id"))
Exemple #2
0
class Quiz(db.Model):
    __tablename__ = "quizzes"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text, nullable=False)
    info = db.Column(db.Text, nullable=False)
    submissions = db.relationship(
        "Submission",
        backref="quiz",
        lazy="dynamic",
        primaryjoin="Submission.quiz_id == Quiz.id",
    )
    questions = db.relationship(
        "Question",
        backref="quiz",
        lazy="dynamic",
        primaryjoin="Question.quiz_id == Quiz.id",
    )
    events = db.relationship(
        "Report",
        backref="quiz",
        lazy="dynamic",
        primaryjoin="Report.quiz_id == Quiz.id",
    )
    owner_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    open_time = db.Column(db.DateTime)
    close_time = db.Column(db.DateTime)

    show_results = db.Column(db.Boolean, default=False)
Exemple #3
0
class Submission(db.Model):
    __tablename__ = "submissions"

    id = db.Column(db.Integer, primary_key=True)
    options = db.Column(db.ARRAY(db.String))
    scores = db.Column(db.ARRAY(db.Integer))
    owner_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    quiz_id = db.Column(db.Integer, db.ForeignKey("quizzes.id"))
    start_time = db.Column(db.DateTime, default=datetime.utcnow)
    is_done = db.Column(db.Boolean, default=False)

    events = db.relationship(
        "Report",
        backref="submission",
        lazy="dynamic",
        primaryjoin="Report.submission_id == Submission.id",
    )
Exemple #4
0
class Question(db.Model):
    __tablename__ = "questions"

    id = db.Column(db.Integer, primary_key=True)
    question = db.Column(db.Text, nullable=False)
    answer = db.Column(db.Text, nullable=False)
    is_essay = db.Column(db.Boolean, nullable=False)
    options = db.Column(db.ARRAY(db.String))
    quiz_id = db.Column(db.Integer, db.ForeignKey("quizzes.id"))
Exemple #5
0
class User(db.Model):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, index=True, nullable=False, unique=True)
    password_hash = db.Column(db.String)
    role_id = db.Column(db.Integer, db.ForeignKey("roles.id"))
    name = db.Column(db.Text)
    quizzes = db.relationship("Quiz",
                              backref="owner",
                              lazy="dynamic",
                              primaryjoin="Quiz.owner_id == User.id")
    submissions = db.relationship(
        "Submission",
        backref="owner",
        lazy="dynamic",
        primaryjoin="Submission.owner_id == User.id",
    )
    classroom_ = db.Column("classroom", db.Integer, nullable=False, default=99)

    @staticmethod
    @login_manager.user_loader
    def load_user(user_id):
        return User.query.get(int(user_id))

    is_active = True
    is_authenticated = True
    is_anonymous = False
    is_admin = db.Column(db.Boolean, default=False)

    def get_id(self):
        return str(self.id)

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    @property
    def classroom(self):
        return ClassEnum(self.classroom_)