Esempio n. 1
0
class UserModel(db.Model):
    __tablename__ = 'user'

    id = db.Column(
        'id',
        db.String(40), nullable=False,
        primary_key=True, default=generators.user)
    email = db.Column(
        'email',
        db.String(256), nullable=False, unique=True, index=True)
    realname = db.Column(
        'realname',
        db.Unicode(128), nullable=False, index=True)
    introduction = db.Column(
        'introduction',
        db.Unicode(1024), nullable=True)
    password_hash = db.Column(
        'password_hash', db.CHAR(40), nullable=False)
    gender = db.Column(
        'gender',
        db.Enum('male', 'femail', 'unknown',
                name='user_gender_enum'))
    avatar = db.Column(
        'avatar',
        db.String(1024), nullable=False,
        default=app.config['DEFAULT_USER_AVATAR'])
    date_created = db.Column(
        'date_created',
        db.DateTime(timezone=True),
        server_default=db.func.current_timestamp())
    date_last_signed_in = db.Column(
        'date_last_signed_in',
        db.DateTime(timezone=True),
        server_default=db.func.current_timestamp())

    @hybrid_property
    def email_insensitive(self):
        return self.email.lower()

    @email_insensitive.comparator
    def email_insensitive_comparator(cls):
        return CaseInsensitiveComparator(cls.email)

    def as_dict(self):
        return dict(
            realname=self.realname,
            email=self.email,
            introduction=self.introduction,
            gender=self.gender,
            avatar=self.avatar,
            date_created=self.date_created)
Esempio n. 2
0
class EmailTempModel(db.Model):
    id = db.Column('id', db.String(40), nullable=False,
                   primary_key=True, default=generators.email_temp)
    email = db.Column('email', db.String(256), nullable=False,
                      unique=True, index=True)
    random_code = db.Column('random_code', db.String(64), nullable=False)
    date_created = db.Column('date_created',
                             db.DateTime(timezone=True),
                             server_default=db.func.current_timestamp(),
                             nullable=False,
                             index=True)

    @property
    def url(self):
        return url_for('account.confirm_email',
                       email=self.email, random_code=self.random_code,
                       _external=True)

    @hybrid_property
    def email_insensitive(self):
        return self.email.lower()

    @email_insensitive.comparator
    def email_insensitive_comparator(cls):
        return CaseInsensitiveComparator(cls.email)
Esempio n. 3
0
class CrossModel(db.Model):
    __tablename__ = 'cross'

    id = db.Column(
        'id',
        db.String(40), nullable=False,
        primary_key=True, default=generators.cross)
    project_id = db.Column(
        'project_id',
        db.String(40), nullable=False,
        index=True)
    is_start = db.Column(
        'is_start',
        db.Boolean(), nullable=False,
        server_default='false')
    is_end = db.Column(
        'is_end',
        db.Boolean(), nullable=False,
        server_default='false')
    date_created = db.Column(
        'date_created',
        db.DateTime(timezone=True),
        server_default=db.func.current_timestamp())

    @classmethod
    def __declare_last__(cls):
        cls.documents = db.relationship(
            'DocumentModel',
            secondary=CrossDocumentModel.__table__,
            backref=db.backref(
                'crosses',
                innerjoin=True,
                order_by=CrossDocumentModel.date_created.desc(),
                lazy='dynamic'),
            primaryjoin=CrossModel.id == CrossDocumentModel.cross_id,
            secondaryjoin=CrossDocumentModel.document_id == DocumentModel.id,
            order_by=CrossDocumentModel.date_created.desc(),
            foreign_keys=[CrossDocumentModel.cross_id,
                          CrossDocumentModel.document_id],
            passive_deletes='all', lazy='dynamic')

        cls.down_tasks = db.relationship(
            'TaskModel',
            secondary=CrossInTaskModel.__table__,
            backref=db.backref(
                'up_cross',
                innerjoin=True,
                uselist=False),
            primaryjoin=CrossModel.id == CrossInTaskModel.cross_id,
            secondaryjoin=CrossInTaskModel.task_id == TaskModel.id,
            order_by=CrossInTaskModel.date_created,
            foreign_keys=[CrossInTaskModel.cross_id,
                          CrossInTaskModel.task_id],
            passive_deletes='all', lazy='subquery')
Esempio n. 4
0
class CrossInTaskModel(db.Model):
    __tablename__ = 'cross_in_task'

    cross_id = db.Column(
        'cross_id',
        db.String(40), nullable=False,
        primary_key=True)
    task_id = db.Column(
        'task_id',
        db.String(40), nullable=False,
        primary_key=True)
    date_created = db.Column(
        'date_created',
        db.DateTime(timezone=True),
        server_default=db.func.current_timestamp())
Esempio n. 5
0
class StaffModel(db.Model):
    __tablename__ = 'staff'

    id = db.Column(
        'id',
        db.String(40), nullable=False,
        primary_key=True, default=generators.staff)
    user_id = db.Column(
        'user_id',
        db.String(40), nullable=False,
        index=True)
    company_id = db.Column(
        'company_id',
        db.String(40), nullable=False,
        index=True)
    date_created = db.Column(
        'date_created',
        db.DateTime(timezone=True),
        server_default=db.func.current_timestamp())
Esempio n. 6
0
class MemberModel(db.Model):
    __tablename__ = 'member'

    id = db.Column(
        'id',
        db.String(40), nullable=False,
        primary_key=True, default=generators.member)
    user_id = db.Column(
        'user_id',
        db.String(40), nullable=False,
        index=True)
    project_id = db.Column(
        'project_id',
        db.String(40), nullable=False,
        index=True)
    date_created = db.Column(
        'date_created',
        db.DateTime(timezone=True),
        server_default=db.func.current_timestamp())
Esempio n. 7
0
class CompanyModel(db.Model):
    __tablename__ = 'company'

    id = db.Column(
        'id',
        db.String(40), nullable=False,
        primary_key=True, default=generators.company)
    name = db.Column(
        'name',
        db.Unicode(256), nullable=False, index=True)
    admin_user_id = db.Column(
        'admin_user_id',
        db.String(40), nullable=False,
        index=True)
    date_created = db.Column(
        'date_created',
        db.DateTime(timezone=True),
        server_default=db.func.current_timestamp())
    staffs_count = db.Column(
        'staffs_count',
        db.Integer(), nullable=False,
        default=0, server_default='0')
    projects_count = db.Column(
        'projects_count',
        db.Integer(), nullable=False,
        default=0, server_default='0')

    staffs = db.relationship(
        'StaffModel',
        backref=db.backref('company', lazy='joined', innerjoin=True),
        primaryjoin='StaffModel.company_id==CompanyModel.id',
        foreign_keys='[StaffModel.company_id]',
        passive_deletes='all',
        lazy='dynamic')

    projects = db.relationship(
        'ProjectModel',
        backref=db.backref('company', lazy='joined', innerjoin=True),
        primaryjoin='ProjectModel.company_id==CompanyModel.id',
        foreign_keys='[ProjectModel.company_id]',
        passive_deletes='all',
        lazy='dynamic')
Esempio n. 8
0
class DocumentModel(db.Model):
    __tablename__ = 'document'

    id = db.Column(
        'id',
        db.String(40), nullable=False,
        primary_key=True, default=generators.document)
    project_id = db.Column(
        'project_id',
        db.String(40), nullable=False,
        index=True)
    name = db.Column(
        'name',
        db.Unicode(256), nullable=False)
    url = db.Column(
        'url',
        db.Unicode(1024), nullable=False)
    date_created = db.Column(
        'date_created',
        db.DateTime(timezone=True),
        server_default=db.func.current_timestamp())
Esempio n. 9
0
class TaskModel(db.Model):
    __tablename__ = 'task'

    id = db.Column(
        'id',
        db.String(40), nullable=False,
        primary_key=True, default=generators.task)
    user_id = db.Column(
        'user_id',
        db.String(40), nullable=False)
    project_id = db.Column(
        'project_id',
        db.String(40), nullable=False)
    name = db.Column(
        'name',
        db.Unicode(256), nullable=False)
    description = db.Column(
        'description',
        db.Unicode(256), nullable=True,
        server_default='')
    is_ready = db.Column(
        'is_ready',
        db.Boolean(), nullable=False,
        default=False,
        server_default='false')
    is_finished = db.Column(
        'is_finished',
        db.Boolean(), nullable=False,
        default=False,
        server_default='false')
    progress = db.Column(
        'progress',
        db.Integer(), nullable=False,
        server_default='0')
    date_start = db.Column(
        'date_start',
        db.DateTime(timezone=True),
        nullable=False,
        server_default=db.func.current_timestamp())
    date_end = db.Column(
        'date_end',
        db.DateTime(timezone=True),
        nullable=False,
        server_default=db.func.current_timestamp())
    date_created = db.Column(
        'date_created',
        db.DateTime(timezone=True),
        nullable=False,
        server_default=db.func.current_timestamp())

    @classmethod
    def __declare_last__(cls):
        cls.down_crosses = db.relationship(
            'CrossModel',
            secondary=TaskOutCrossModel.__table__,
            backref=db.backref(
                'up_tasks',
                innerjoin=True,
                order_by=TaskOutCrossModel.date_created,
                lazy='subquery'),
            primaryjoin=TaskModel.id == TaskOutCrossModel.task_id,
            secondaryjoin=TaskOutCrossModel.cross_id == CrossModel.id,
            order_by=TaskOutCrossModel.date_created,
            foreign_keys=[TaskOutCrossModel.task_id,
                          TaskOutCrossModel.cross_id],
            passive_deletes='all', lazy='subquery')
Esempio n. 10
0
class ProjectModel(db.Model):
    __tablename__ = 'project'

    id = db.Column(
        'id',
        db.String(40), nullable=False,
        primary_key=True, default=generators.project)
    company_id = db.Column(
        'company_id',
        db.String(40), nullable=False,
        index=True)
    manage_user_id = db.Column(
        'manage_user_id',
        db.String(40), nullable=False,
        index=True)
    name = db.Column(
        'name',
        db.Unicode(256), nullable=False, index=True)
    date_created = db.Column(
        'date_created',
        db.DateTime(timezone=True),
        server_default=db.func.current_timestamp())
    members_count = db.Column(
        'members_count',
        db.Integer(), nullable=False,
        default=0, server_default='0')
    tasks_count = db.Column(
        'tasks_count',
        db.Integer(), nullable=False,
        default=0, server_default='0')
    crosses_count = db.Column(
        'crosses_count',
        db.Integer(), nullable=False,
        default=0, server_default='0')
    documents_count = db.Column(
        'documents_count',
        db.Integer(), nullable=False,
        default=0, server_default='0')

    members = db.relationship(
        'MemberModel',
        backref=db.backref('project', lazy='joined', innerjoin=True),
        primaryjoin='MemberModel.project_id==ProjectModel.id',
        foreign_keys='[MemberModel.project_id]',
        passive_deletes='all',
        lazy='dynamic')

    documents = db.relationship(
        'DocumentModel',
        backref=db.backref('project', lazy='joined', innerjoin=True),
        primaryjoin='DocumentModel.project_id==ProjectModel.id',
        foreign_keys='[DocumentModel.project_id]',
        passive_deletes='all',
        lazy='dynamic')

    crosses = db.relationship(
        'CrossModel',
        backref=db.backref('project', lazy='joined', innerjoin=True),
        primaryjoin='CrossModel.project_id==ProjectModel.id',
        foreign_keys='[CrossModel.project_id]',
        passive_deletes='all',
        lazy='dynamic')

    cross_start = db.relationship(
        'CrossModel',
        primaryjoin=('and_(CrossModel.project_id==ProjectModel.id, '
                     'CrossModel.is_start)'),
        foreign_keys='[CrossModel.project_id]',
        passive_deletes='all',
        uselist=False,
        lazy='joined')

    cross_end = db.relationship(
        'CrossModel',
        primaryjoin=('and_(CrossModel.project_id==ProjectModel.id, '
                     'CrossModel.is_end)'),
        foreign_keys='[CrossModel.project_id]',
        passive_deletes='all',
        uselist=False,
        lazy='joined')

    tasks = db.relationship(
        'TaskModel',
        backref=db.backref('project', lazy='joined', innerjoin=True),
        primaryjoin='TaskModel.project_id==ProjectModel.id',
        foreign_keys='[TaskModel.project_id]',
        passive_deletes='all',
        lazy='dynamic')