Exemple #1
0
class WorkspaceDate(Base, Persistent):
    __tablename__ = 'workspace_date'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)
    ws_id = db.Column(db.Integer, db.ForeignKey('workspace.id'))
    date = db.Column(db.Date, nullable=False)
    is_official_holiday = db.Column(db.Boolean(), nullable=True)

    @staticmethod
    def get_work_days_count(ws_id, start_date, end_date):
        holidays = WorkspaceDate.query(). \
            filter(WorkspaceDate.date.between(start_date, end_date)). \
            filter(WorkspaceDate.ws_id == ws_id). \
            filter(WorkspaceDate.is_official_holiday is True). \
            all()

        result = 0

        holiday_dates = map(lambda h: h.date, holidays)

        date = start_date

        while date <= end_date:
            if date.weekday() < 5 and date not in holiday_dates:
                result += 1

            date = date + datetime.timedelta(days=1)

        return result
Exemple #2
0
class WorkspaceModel(Base, Persistent):
    __tablename__ = 'workspace'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True, nullable=False)
    description = db.Column(db.String(255))
    invitation_link_token = db.Column(db.String(255))

    @staticmethod
    def generate_invitation_link_token():
        return str(uuid.uuid4())

    @classmethod
    def find_by_user_id(cls, user_id):
        ws_ids = [x.ws_id for x in WorkspaceUser.find_all(user_id=user_id)]
        return cls.query().filter(WorkspaceModel.id.in_(ws_ids))
Exemple #3
0
class User(Base, Persistent):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    password = db.Column(db.String(120), nullable=False)
    created_time = db.Column(db.DateTime(), nullable=False)
    jti = db.Column(db.String, nullable=True)
    email = db.Column(db.String(120), unique=True, nullable=False)

    @classmethod
    def find_by_email(cls, email):
        return cls.find(email=email)

    @staticmethod
    def generate_hash(password):
        return sha256.hash(password)

    @staticmethod
    def verify_hash(password, password_hash):
        return sha256.verify(password, password_hash)
Exemple #4
0
class Balance:
    __tablename__ = 'balance'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column('user_id', db.Integer, db.ForeignKey('user.id'), nullable=False)
    # user = db.relationship('User', backref='balances', foreign_keys=[user_id])
    balance_type = db.Column('balance_type', db.String(120), nullable=False)
    amount = db.Column('amount', db.Integer, nullable=False)

    @classmethod
    def find_by_user_id(cls, user_id):
        return cls.find_all(user_id=user_id)
Exemple #5
0
class WorkspaceInvitation(Base, Persistent):
    __tablename__ = 'workspace_invitation'

    id = db.Column(db.Integer(), primary_key=True)
    email = db.Column(db.String(255), nullable=False)
    ws_id = db.Column(db.Integer,
                      db.ForeignKey('workspace.id'),
                      nullable=False)
    status = db.Column(db.Enum(WorkspaceInvitationStatus),
                       default=WorkspaceInvitationStatus.PENDING,
                       nullable=False)
    start_date = db.Column(db.Date, nullable=True)
Exemple #6
0
class UserModel(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(120), nullable=False)

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def find_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @staticmethod
    def generate_hash(password):
        return sha256.hash(password)

    @staticmethod
    def verify_hash(password, password_hash):
        return sha256.verify(password, password_hash)
Exemple #7
0
class RevokedTokenModel(db.Model):
    __tablename__ = 'revoked_token'
    id = db.Column(db.Integer, primary_key=True)
    jti = db.Column(db.String(120))

    def add(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def is_jti_blacklisted(cls, jti):
        query = cls.query.filter_by(jti=jti).first()
        return bool(query)
Exemple #8
0
class DayOff(Base, Persistent):
    __tablename__ = 'day_off'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column('user_id', db.Integer, db.ForeignKey('user_profile.user_id'), nullable=False)
    user = db.relationship('UserProfile', foreign_keys=[user_id])

    approved_by_id = db.Column('approved_by_id', db.Integer, db.ForeignKey('user_profile.user_id'), nullable=True)
    approved_by = db.relationship('UserProfile', foreign_keys=[approved_by_id])

    leave_type = db.Column('leave_type', db.Enum(LeaveTypes), nullable=False)

    start_date = db.Column('start_date', db.Date, nullable=False)
    end_date = db.Column('end_date', db.Date, nullable=False)

    workspace_id = db.Column('workspace_id', db.Integer, db.ForeignKey('workspace.id'), nullable=False)
    workspace = db.relationship('WorkspaceModel', foreign_keys=[workspace_id])

    comment = db.Column('comment', db.String(255), nullable=True)

    @classmethod
    def find_by_user_id(cls, user_id):
        return cls.find_all(user_id=user_id)