示例#1
0
class WorkspaceUserRole(Base, Persistent):
    __tablename__ = 'workspace_user_role'

    ws_id = db.Column(db.Integer,
                      db.ForeignKey('workspace.id'),
                      nullable=False,
                      primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        nullable=False,
                        primary_key=True)
    role = db.Column(db.Enum(WorkspaceUserRoles),
                     default=WorkspaceUserRoles.MEMBER,
                     nullable=False,
                     primary_key=True)
示例#2
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
示例#3
0
class UserDevice(Base, Persistent):
    __tablename__ = 'user_device'

    user_id = db.Column('user_id',
                        db.Integer,
                        db.ForeignKey('user.id'),
                        nullable=False)
    device_token = db.Column('device_token',
                             db.String,
                             primary_key=True,
                             nullable=False)
示例#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)
示例#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)
示例#6
0
class WorkspaceUser(Base, Persistent):
    __tablename__ = 'workspace_user'

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    ws_id = db.Column(db.Integer,
                      db.ForeignKey('workspace.id'),
                      primary_key=True)
    start_date = db.Column(db.Date,
                           default=datetime.datetime.now(),
                           nullable=False)

    profile = db.relationship(
        'UserProfile',
        primaryjoin='foreign(UserProfile.user_id) == WorkspaceUser.user_id',
        uselist=False,
        viewonly=True)

    def get_worked_months(self):
        now = datetime.datetime.now()
        return (now.year -
                self.start_date.year) * 12 + now.month - self.start_date.month
示例#7
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)
示例#8
0
class WorkspaceRule(Base, Persistent):
    __tablename__ = 'workspace_rule'

    ws_id = db.Column(db.Integer,
                      db.ForeignKey('workspace.id'),
                      nullable=False,
                      primary_key=True)
    type = db.Column(db.Enum(WorkspaceRuleTypes),
                     nullable=False,
                     primary_key=True)
    rule = db.Column(db.String, nullable=False)
    node = db.Column(db.BLOB, nullable=True)

    def __init__(self, ws_id, type, rule):
        self.ws_id = ws_id
        self.type = type
        self.rule = rule
        self.node = pickle.dumps(Intellect().learn_policy(rule))
示例#9
0
class UserProfile(Base, Persistent):
    __tablename__ = 'user_profile'

    user_id = db.Column('user_id',
                        db.Integer,
                        db.ForeignKey('user.id'),
                        primary_key=True,
                        nullable=False)
    first_name = db.Column('first_name', db.String, nullable=True)
    last_name = db.Column('last_name', db.String, nullable=True)
    position = db.Column('position', db.String, nullable=True)
    phone = db.Column('phone', db.String, nullable=True)
    email = db.Column('email', db.String, nullable=False)
    user = db.relationship('User', foreign_keys=[user_id])

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