class UserBranch(db.Model):
    __tablename__ = 'user_has_branch'

    id = db.Column(UuidField,
                   unique=True,
                   nullable=False,
                   default=uuid4,
                   primary_key=True)

    user_id = db.Column(UuidField, db.ForeignKey('user.id'))
    branch_id = db.Column(UuidField, db.ForeignKey('branch.id'))

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)

    user = relationship(User,
                        backref=backref("branches",
                                        cascade="all, delete-orphan"))
    branch = relationship(Branch,
                          backref=backref("users",
                                          cascade="all, delete-orphan"))
Example #2
0
class UserGroupStudentClass(db.Model):
    __tablename__ = 'user_group_has_class'

    id = db.Column(UuidField,
                   unique=True,
                   nullable=False,
                   default=uuid4,
                   primary_key=True)

    userGroup_id = db.Column(UuidField, db.ForeignKey('user_group.id'))
    studentClass_id = db.Column(UuidField, db.ForeignKey('student_class.id'))

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)

    userGroup = relationship(UserGroup,
                             backref=backref("classes",
                                             cascade="all, delete-orphan"))
    studentClass = relationship(StudentClass,
                                backref=backref("groups",
                                                cascade="all, delete-orphan"))
class BranchAddress(db.Model):
    __tablename__ = 'branch_has_address'

    id = db.Column(UuidField,
                   unique=True,
                   nullable=False,
                   default=uuid4,
                   primary_key=True)

    branch_id = db.Column(UuidField, db.ForeignKey('branch.id'))
    address_id = db.Column(UuidField, db.ForeignKey('address.id'))

    is_current_address = db.Column(db.Boolean,
                                   unique=False,
                                   nullable=False,
                                   default=False)

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)

    branch = relationship(Branch,
                          backref=backref("addresses",
                                          cascade="all, delete-orphan"))
    address = relationship(Address,
                           backref=backref("branches",
                                           cascade="all, delete-orphan"))
Example #4
0
class StudentClass(db.Model):
    id = db.Column(UuidField,
                   unique=True,
                   nullable=False,
                   default=uuid4,
                   primary_key=True)
    name = db.Column(db.String(255), unique=False, nullable=False)

    tax = db.Column(db.String(255), unique=False, nullable=True)
    coc = db.Column(db.String(255), unique=False, nullable=True)

    default_time = db.Column(db.DateTime)
    current_time = db.Column(db.DateTime)

    is_cancelt = db.Column(db.Boolean, default=False)
    is_attendance_required = db.Column(db.Boolean, default=True)

    defaultRoom_id = db.Column(UuidField,
                               db.ForeignKey('room.id'),
                               nullable=False)
    currentRoom_id = db.Column(UuidField,
                               db.ForeignKey('room.id'),
                               nullable=True)

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)
class UserAddress(db.Model):
    __tablename__ = 'user_has_address'

    id = db.Column(UuidField,
                   unique=True,
                   nullable=False,
                   default=uuid4,
                   primary_key=True)

    user_id = db.Column(UuidField, db.ForeignKey('user.id'))
    address_id = db.Column(UuidField, db.ForeignKey('address.id'))

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)

    user = relationship(User,
                        backref=backref("addresses",
                                        cascade="all, delete-orphan"))
    address = relationship(Address,
                           backref=backref("users",
                                           cascade="all, delete-orphan"))
Example #6
0
class GroupUser(db.Model):
    __tablename__ = 'group_has_user'

    id = db.Column(UuidField, unique=True, nullable=False, default=uuid4, primary_key=True)

    user_id = db.Column(UuidField, db.ForeignKey('user.id'))
    userGroup_id = db.Column(UuidField, db.ForeignKey('user_group.id'))

    date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    date_updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)

    user = relationship(User, backref=backref("group", cascade="all, delete-orphan"))
    group = relationship(UserGroup, backref=backref("user", cascade="all, delete-orphan"))
Example #7
0
class UserOrganisation(db.Model, Crud):
    __tablename__ = 'user_has_organisation'

    id = db.Column(UuidField,
                   unique=True,
                   nullable=False,
                   default=uuid4,
                   primary_key=True)

    user_id = db.Column(UuidField, db.ForeignKey('user.id'))
    organisation_id = db.Column(UuidField, db.ForeignKey('organisation.id'))

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)

    user = relationship('User',
                        backref=backref("organisations",
                                        cascade="all, delete-orphan"))
    organisation = relationship('Organisation',
                                backref=backref("users",
                                                cascade="all, delete-orphan"))

    @classmethod
    def find(cls, user_id, organisation_id) -> 'UserOrganisation':
        return cls.query\
            .filter(UserOrganisation.user_id == user_id)\
            .filter(UserOrganisation.organisation_id == organisation_id)\
            .first()

    @classmethod
    def link_obj(cls, user_obj: 'User',
                 organisation_obj: 'Organisation') -> 'UserOrganisation':
        return cls.link(user_id=user_obj.id,
                        organisation_id=organisation_obj.id)

    @classmethod
    def link(cls, user_id: str, organisation_id: str) -> 'UserOrganisation':
        return cls(user_id=user_id, organisation_id=organisation_id)

    @classmethod
    def unlink(cls, user_id: str, organisation_id: str):
        obj = cls.find(user_id, organisation_id=organisation_id)
        if obj is None:
            return False
        return obj.delete()
Example #8
0
class UserRelation(db.Model):
    __tablename__ = 'user_has_relation'

    id = db.Column(UuidField, unique=True, nullable=False, default=uuid4, primary_key=True)

    student_id = db.Column(UuidField, db.ForeignKey('user.id'))
    relation_id = db.Column(UuidField, db.ForeignKey('user.id'))
    relationType_id = db.Column(UuidField, db.ForeignKey('relation_type.id'))

    date_created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    date_updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)

    student = relationship(User, foreign_keys=[student_id], backref=backref("relation", cascade="all, delete-orphan"))
    relation = relationship(User, foreign_keys=[relation_id], backref=backref("student", cascade="all, delete-orphan"))
    relationType = relationship(RelationType)
class Authentication(db.Model, Crud):
    key = db.Column(UuidField,
                    unique=True,
                    nullable=False,
                    default=uuid4,
                    primary_key=True)
    expiration = db.Column(db.DateTime, unique=False, nullable=True)

    note = db.Column(db.Text, unique=False, nullable=True)
    note_blocked = db.Column(db.Text, unique=False, nullable=True)

    is_blocked = db.Column(db.Boolean,
                           default=False,
                           nullable=False,
                           unique=False)

    user_id = db.Column(UuidField, db.ForeignKey('user.id'), nullable=False)

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)

    def expires_in(self, delta: relativedelta):
        self.expiration = datetime.now() + delta

    def never_expire(self):
        self.expires_in(relativedelta(years=100))

    @classmethod
    def validate(cls, token: str) -> bool:
        return bool(cls.query.filter_by(key=token).count())
Example #10
0
class Branch(db.Model):
    id = db.Column(UuidField,
                   unique=True,
                   nullable=False,
                   default=uuid4,
                   primary_key=True)
    name = db.Column(db.String(255), unique=False, nullable=False)

    is_main = db.Column(db.Boolean, unique=False, default=False)

    website = db.Column(db.String(255), unique=False, nullable=True)
    phone = db.Column(db.String(255), unique=False, nullable=True)
    email = db.Column(db.String(255), unique=False, nullable=True)

    organisation_id = db.Column(UuidField,
                                db.ForeignKey('organisation.id'),
                                nullable=False)

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)

    rooms = relationship('Room', backref="Branch", lazy=True)
Example #11
0
class Assignment(db.Model):
    id = db.Column(UuidField,
                   unique=True,
                   nullable=False,
                   default=uuid4,
                   primary_key=True)
    name = db.Column(db.String(255), unique=False, nullable=False)

    tax = db.Column(db.String(255), unique=False, nullable=True)
    coc = db.Column(db.String(255), unique=False, nullable=True)

    turned_in = db.Column(db.Boolean, default=False, nullable=False)

    is_group_assignment = db.Column(db.Boolean, default=False, nullable=False)
    is_graded = db.Column(db.Boolean, default=True, nullable=False)

    note = db.Column(db.Text, nullable=True)

    assignmentGroup_id = db.Column(UuidField,
                                   db.ForeignKey('assignment_group.id'),
                                   nullable=False)
    classStart_id = db.Column(UuidField,
                              db.ForeignKey('student_class.id'),
                              nullable=False)
    classDue_id = db.Column(UuidField,
                            db.ForeignKey('student_class.id'),
                            nullable=False)

    date_started = db.Column(db.DateTime,
                             nullable=True,
                             default=datetime.utcnow)
    date_due = db.Column(db.DateTime, nullable=True)

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)
Example #12
0
class Room(db.Model):
    id = db.Column(UuidField,
                   unique=True,
                   nullable=False,
                   default=uuid4,
                   primary_key=True)
    name = db.Column(db.String(255), unique=False, nullable=False)

    branch_id = db.Column(UuidField,
                          db.ForeignKey('branch.id'),
                          nullable=False)

    floor = db.Column(db.String(255), unique=False, nullable=True)
    number = db.Column(db.String(255), unique=False, nullable=True)

    note = db.Column(db.Text, unique=False, nullable=True)

    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)