Esempio n. 1
0
class Teacher(db.Model):
    __tablename__ = 'teachers'

    id = db.Column(UUID,
                   server_default=db.text('gen_random_uuid()'),
                   primary_key=True)
    name = db.Column(db.VARCHAR(255))
    email = db.Column(db.VARCHAR(255))
    subjects = db.relationship('Subject')
Esempio n. 2
0
class CourseTheme(db.Model):
    __tablename__ = 'course_themes'

    id = db.Column(UUID,
                   server_default=db.text('gen_random_uuid()'),
                   primary_key=True)
    name = db.Column(db.VARCHAR(255))
    course_number = db.relationship('CourseNumber')
    course_number_lazy = db.relationship('CourseNumber', lazy='dynamic')
Esempio n. 3
0
class EventLog(db.Model):
    __tablename__ = 'event_log'

    id = db.Column(UUID,
                   server_default=db.text('gen_random_uuid()'),
                   primary_key=True)
    msg = db.Column(db.VARCHAR(255))
    course_number_id = db.Column(UUID, db.ForeignKey('course_numbers.id'))
    course_number = db.relationship('CourseNumber')
Esempio n. 4
0
class CourseGroup(db.Model):
    __tablename__ = 'course_groups'

    id = db.Column(UUID,
                   server_default=db.text('gen_random_uuid()'),
                   primary_key=True)
    gid = db.Column(db.VARCHAR(30))
    course_number_id = db.Column(UUID, db.ForeignKey('course_numbers.id'))
    course_number = db.relationship('CourseNumber')
    students = db.relationship('User')
    class_schedule = db.relationship('ClassSchedule', lazy='dynamic')
Esempio n. 5
0
class ClassSchedule(db.Model):
    __tablename__ = 'class_schedule'

    id = db.Column(UUID,
                   server_default=db.text('gen_random_uuid()'),
                   primary_key=True)
    dow = db.Column(db.VARCHAR(5))
    seq = db.Column(db.INTEGER)
    classroom = db.Column(db.VARCHAR(30))
    course_group_id = db.Column(UUID, db.ForeignKey('course_groups.id'))
    course_group = db.relationship('CourseGroup')
    subject_id = db.Column(UUID, db.ForeignKey('subjects.id'))
    subject = db.relationship('Subject')
Esempio n. 6
0
class CourseNumber(db.Model):
    __tablename__ = 'course_numbers'

    id = db.Column(UUID,
                   server_default=db.text('gen_random_uuid()'),
                   primary_key=True)
    number = db.Column(db.INTEGER, default=0)
    course_theme_id = db.Column(UUID, db.ForeignKey('course_themes.id'))
    course_theme = db.relationship('CourseTheme')
    course_group = db.relationship('CourseGroup')
    subjects = db.relationship('Subject',
                               secondary=course_number_subjects,
                               lazy='dynamic')
Esempio n. 7
0
class Subject(db.Model):
    __tablename__ = 'subjects'

    id = db.Column(UUID,
                   server_default=db.text('gen_random_uuid()'),
                   primary_key=True)
    name = db.Column(db.VARCHAR(255))
    desc = db.Column(db.TEXT)
    teacher_id = db.Column(UUID, db.ForeignKey('teachers.id'))
    teacher = db.relationship('Teacher')
    lessons = db.relationship('ClassSchedule')
    course_subscribed = db.relationship('CourseNumber',
                                        secondary=course_number_subjects,
                                        lazy='dynamic')
Esempio n. 8
0
 def delete(self):
     self.is_deleted = True
     self.deleted_at = db.text('now()::timestamp(0)')
     db.session.commit()
Esempio n. 9
0
 def ban(self):
     self.is_banned = True
     self.banned_at = db.text('now()::timestamp(0)')
     db.session.commit()
Esempio n. 10
0
class User(db.Model):
    """Base user model class."""

    __tablename__ = 'users'

    # identification
    id = db.Column(UUID,
                   server_default=db.text('gen_random_uuid()'),
                   primary_key=True)
    tid = db.Column(db.INTEGER)
    email = db.Column(db.VARCHAR(120))
    password = db.Column(db.VARCHAR(256))
    course_group_id = db.Column(UUID, db.ForeignKey('course_groups.id'))
    course_group = db.relationship('CourseGroup')

    is_admin = db.Column(db.BOOLEAN, default=False)
    is_banned = db.Column(db.BOOLEAN, default=False)
    banned_at = db.Column(db.TIMESTAMP(timezone=True))
    is_deleted = db.Column(db.BOOLEAN, default=False)
    deleted_at = db.Column(db.TIMESTAMP(timezone=True))

    # Tech info
    created_at = db.Column(db.TIMESTAMP(timezone=True),
                           server_default=db.text('now()::timestamp(0)'))

    # password functions
    def hash_password(self, password):
        self.password = generate_password_hash(password, method='pbkdf2:sha256', salt_length=15)

    def verify_password(self, recieved_password):
        return check_password_hash(self.password, recieved_password)

    # token finctions
    def generate_auth_token(self):
        return generate_token(self.id)

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return not self.is_banned

    @property
    def is_anonymous(self):
        return False

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

    @staticmethod
    def verify_auth_token(token):
        token_claimset = verify_token(token)
        if not token_claimset:
            return None
        current_user = User.query.get(token_claimset['id'])

        return current_user

    # ban function
    def ban(self):
        self.is_banned = True
        self.banned_at = db.text('now()::timestamp(0)')
        db.session.commit()

    def ban_recovery(self):
        self.is_banned = False
        self.banned_at = None
        db.session.commit()

    # delete function
    def delete(self):
        self.is_deleted = True
        self.deleted_at = db.text('now()::timestamp(0)')
        db.session.commit()

    def recovery(self):
        self.is_deleted = False
        self.deleted_at = None
        db.session.commit()