Exemplo n.º 1
0
class UsersRoles(db.Model):
    __tablename__ = "users_roles"
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id",
                                                  ondelete="CASCADE"))
    role_id = db.Column(db.Integer,
                        db.ForeignKey("roles.id", ondelete="CASCADE"))
Exemplo n.º 2
0
class CompetitionSubmission(db.Model):
    __tablename__ = "competition_submission"
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    competition_id = db.Column(db.Integer, db.ForeignKey("competition.id"))
    submit_date = db.Column(db.DateTime, default=datetime.datetime.now())
    file_name = db.Column(db.String, nullable=False)
    description = db.Column(db.String, nullable=True)
Exemplo n.º 3
0
class CompetitionScore(db.Model):
    __tablename__ = "competition_score"
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    competition_id = db.Column(db.Integer, db.ForeignKey("competition.id"))
    submission_id = db.Column(db.Integer,
                              db.ForeignKey("competition_submission.id"))
    score = db.Column(db.Numeric, nullable=True)
Exemplo n.º 4
0
class CompetitionAttendee(db.Model):
    __tablename__ = "competition_attendee"
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    competition_id = db.Column(db.Integer, db.ForeignKey("competition.id"))
    attended_date = db.Column(db.DateTime, default=datetime.datetime.now())
    quit_date = db.Column(db.DateTime, default=None)
    is_active = db.Column(db.Boolean, default=True)
Exemplo n.º 5
0
class User(db.Model, UserMixin):
    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String, unique=True)
    username = db.Column(db.String, unique=True)
    password_hash = db.Column(db.String(128))
    group_id = db.Column(db.Integer, db.ForeignKey("user_group.id"), default=1)
    last_seen = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    from_ = db.Column(db.DateTime, default=datetime.datetime.utcnow())
    # Relationships
    roles = db.relationship("Roles",
                            secondary="users_roles",
                            backref=db.backref("user", lazy="dynamic"))

    def get_id(self):
        return 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)

    def avatar(self, size):
        digest = md5(self.email.lower().encode("utf-8")).hexdigest()
        return "https://www.gravatar.com/avatar/{}?d=identicon&s={}".format(
            digest, size)
Exemplo n.º 6
0
class Competition(db.Model):
    __tablename__ = "competition"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True)
    friendly_name = db.Column(db.String, nullable=True)
    description_overview = db.Column(db.String, nullable=True)
    description_eval = db.Column(db.String, nullable=True)
    description_data = db.Column(db.String, nullable=True)
    metric_type = db.Column(db.String, nullable=False)
    metric_name = db.Column(db.String, nullable=False)
    creator_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    access_level = db.Column(db.Integer)  # 1:personal, 2:group, 3:public
    created_date = db.Column(db.DateTime, default=datetime.datetime.now())
    deadline_date = db.Column(db.DateTime, nullable=True)
    is_open = db.Column(db.Boolean, default=True, nullable=False)

    def is_user_joined(self, user_id):
        res = (CompetitionAttendee.query.filter(
            CompetitionAttendee.competition_id == self.id).filter(
                CompetitionAttendee.user_id == user_id).first())
        if res:
            return True
        return False
Exemplo n.º 7
0
class CompetitionActivity(db.Model):
    __tablename__ = "competition_activity"
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    competition_id = db.Column(db.Integer, db.ForeignKey("competition.id"))
    content = db.Column(db.String, nullable=False)
Exemplo n.º 8
0
class UsersTeams(db.Model):
    __tablename__ = "users_teams"
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    team_id = db.Column(db.Integer, db.ForeignKey("user_team.id"))
    from_ = db.Column(db.DateTime, default=datetime.datetime.utcnow())
Exemplo n.º 9
0
class GeneralActivity(db.Model):
    __tablename__ = "general_activity"
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime, default=datetime.datetime.utcnow())
    content = db.Column(db.String, unique=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))