class QuestionSetToTag(db.Model):
    __tablename__ = "question_set_to_tag"
    question_set_id = db.Column(db.Integer,
                                db.ForeignKey("question_set.id"),
                                primary_key=True)
    tag_id = db.Column(db.Integer,
                       db.ForeignKey("question_set_tag.id"),
                       primary_key=True)

    question_set = db.relationship("QuestionSet", back_populates="tags")
    tag = db.relationship("QuestionSetTag", back_populates="question_sets")

    difficulty_level = db.Column(db.String(32))
Beispiel #2
0
class UserAccount(db.Model):
    __tablename__ = 'user_account'

    user_id = db.Column(db.Integer,
                        db.ForeignKey('user_profile.id'),
                        primary_key=True,
                        nullable=False)
    email = db.Column(db.String(128), nullable=False)
    password_hash = db.Column(db.String(128), nullable=False)
    password_reset_tok = db.Column(db.String(128))
    password_reset_exp = db.Column(db.TIMESTAMP)
    user_state = db.Column(db.String(32),
                           nullable=False,
                           server_default=UserState.UNVERIFIED.value)

    user_profile = db.relationship("UserProfile",
                                   backref=db.backref("user_account",
                                                      uselist=False))

    def set_password(self, password: str) -> None:
        self.password_hash = generate_password_hash(password)

    def check_password(self, password: str) -> bool:
        return check_password_hash(self.password_hash, password)

    def check_code(self, code: str) -> bool:
        return self.password_reset_tok == code

    def set_email_as_verified(self) -> None:
        self.user_state = UserState.VERIFIED.value
Beispiel #3
0
class QuestionSet(db.Model):
    __tablename__ = "question_set"

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    name = db.Column(db.String(128), unique=True, nullable=False)
    details = db.Column(db.Text, nullable=False)
    creation_date = db.Column(db.TIMESTAMP,
                              nullable=False,
                              default=datetime.now)
    owner_id = db.Column(db.Integer,
                         db.ForeignKey("user_profile.id"),
                         nullable=False)
    close_date = db.Column(db.TIMESTAMP)
    open_date = db.Column(db.TIMESTAMP)

    to_update = db.Column(db.Boolean, server_default="0")

    owner_profile = db.relationship("UserProfile",
                                    backref=db.backref("question_sets",
                                                       lazy=True))

    tags = db.relationship("QuestionSetToTag", back_populates="question_set")

    @hybrid_property
    def question_count(self):
        return len(self.questions)

    @question_count.expression
    def question_count(cls):
        return func.count(cls.questions)

    @hybrid_property
    def report_count(self):
        return len(self.reports)
Beispiel #4
0
class QuestionAnswer(db.Model):
    __tablename__ = "question_answer"

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("user_profile.id"),
                        nullable=False)
    question_id = db.Column(db.Integer,
                            db.ForeignKey("question.id"),
                            nullable=False)
    payload = db.Column(db.JSON, nullable=False)
    creation_time = db.Column(db.TIMESTAMP,
                              nullable=False,
                              default=datetime.now)

    question = db.relationship("Question",
                               backref=db.backref("answers", lazy=True))
    user = db.relationship("UserProfile",
                           backref=db.backref("answered_questions", lazy=True))
Beispiel #5
0
class QuestionSetReport(db.Model):
    __tablename__ = "question_set_report"

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("user_profile.id"),
                        nullable=False)
    question_set_id = db.Column(db.Integer,
                                db.ForeignKey("question_set.id"),
                                nullable=False)
    type = db.Column(db.String(128), nullable=False)
    details = db.Column(db.String(255), nullable=False)
    creation_time = db.Column(db.TIMESTAMP,
                              nullable=False,
                              default=datetime.now)

    question_set = db.relationship("QuestionSet",
                                   backref=db.backref("reports", lazy=True))
    user = db.relationship("UserProfile",
                           backref=db.backref("reports_sent", lazy=True))
class OAuth2Account(db.Model):
    __tablename__ = "oauth2_account"

    client_id = db.Column(db.Integer, primary_key=True, nullable=False)
    client_secret = db.Column(db.Integer, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey("user_profile.id"), nullable=False)
    provider = db.Column(db.Integer, nullable=False)

    user_profile = db.relationship(
        "UserProfile", backref=db.backref("user_profile", uselist=False)
    )
Beispiel #7
0
class PromotionAction(db.Model):
    __tablename__ = "promotion_action"

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    question_set_id = db.Column(db.Integer,
                                db.ForeignKey("question_set.id"),
                                nullable=False)
    type = db.Column(db.String(128), nullable=False)
    start_time = db.Column(db.TIMESTAMP, nullable=False)
    end_time = db.Column(db.TIMESTAMP)

    question_set = db.relationship("QuestionSet",
                                   backref=db.backref("promotion_actions",
                                                      lazy=True))
Beispiel #8
0
class Question(db.Model):
    __tablename__ = "question"

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    question_set_id = db.Column(db.Integer,
                                db.ForeignKey("question_set.id"),
                                nullable=False)
    payload = db.Column(db.JSON, nullable=False)

    question_set = db.relationship("QuestionSet",
                                   backref=db.backref("questions", lazy=True))

    @hybrid_property
    def answer_count(self):
        return len(self.answers)