class Task(SurrogatePK, Model): __tablename__ = 'tasks' task_name = Column(db.Text(), unique=False, nullable=True, index=True) task_desc = Column(db.Text(), unique=False, nullable=True) start_date = Column(db.Date(), unique=False, nullable=False, index=True) end_date = Column(db.Date(), unique=False, nullable=True, index=True) # one-to-many user to tasks creator_id = db.Column('creator_id', db.Integer, db.ForeignKey('users.id')) # ref to optional associated case case_id = db.Column('case_id', db.Integer, db.ForeignKey('cases.id'), nullable=True) # many-to-many users to tasks assignees = relationship('User', secondary=task_user_map, backref=db.backref('user_tasks', lazy='dynamic')) # ref to optional associated project project_id = db.Column('project_id', db.Integer, db.ForeignKey('projects.id'), nullable=True) def __init__(self, *args, **kwargs): db.Model.__init__(self, *args, **kwargs) def __repr__(self): return '<Task(id={id}, task_name={task_name}, )>'.format( id=self.id, task_name=self.task_name)
class Tag(SurrogatePK, Model): __tablename__ = 'tags' kind = Column(db.Text(), nullable=False, index=True) tag = Column(db.Text(), nullable=False, index=True) def __init__(self, **kwargs): db.Model.__init__(self, **kwargs) def __repr__(self): return '<Tag(id={id}, kind={kind}, tag={tag})>'.format( tag=self.tag, id=self.id, kind=self.kind)
class CaseFile(SurrogatePK, Model): __tablename__ = 'case_files' kind = db.Column(db.Text(), unique=False) name = db.Column(db.Text(), unique=False) path = db.Column(db.Text(), unique=False) attributes = db.Column(db.Text(), unique=False, nullable=True) case_id = ReferenceCol('cases', nullable=False) def __init__(self, *args, **kwargs): db.Model.__init__(self, *args, **kwargs) def __repr__(self): return '<CaseFile(id={id}, kind={kind}, name={name})>'.format( id=self.id, kind=self.kind, name=self.name)
class Case(SurrogatePK, Model): __tablename__ = 'cases' crd_number = Column(db.Text(), unique=False, nullable=False, index=True) case_name = Column(db.Text(), unique=False, nullable=True, index=True) case_desc = Column(db.Text(), unique=False, nullable=True) start_date = Column(db.Date(), unique=False, nullable=False, index=True) end_date = Column(db.Date(), unique=False, nullable=True, index=True) case_type_id = ReferenceCol('case_types', nullable=False) case_type = relationship('CaseType', backref='case_types') case_status_id = ReferenceCol('case_statuses', nullable=True, colname='case_status_id', parent_table='cases') case_status = relationship('CaseStatus', backref='case_statuses') region_id = ReferenceCol('regions', nullable=False) region = relationship('Region', backref='regions') users = association_proxy('user_cases', 'user') mars_risk_score = Column(db.Integer, unique=False, nullable=True) qau_risk_score = Column(db.Integer, unique=False, nullable=True) examiner_risk_score = Column(db.Integer, unique=False, nullable=True) tags = relationship('Tag', secondary=case_tag_map, backref=db.backref('cases', lazy='dynamic')) files = relationship('CaseFile', backref='case_files') tasks = relationship('Task', backref='case_tasks') def __init__(self, *args, **kwargs): db.Model.__init__(self, *args, **kwargs) def get_tags(self, kind=None): """ Get a case's tags, class must be initialized first :param kind: risk | non_qau_staff | None :return: list of unicode tags according to the specified kind """ if kind: return [i.tag for i in self.tags if i.kind == kind] else: return [i.tag for i in self.tags] def __repr__(self): return '<Case(id={id}, case_name={case_name}, )>'.format( id=self.id, case_name=self.case_name)
class Project(SurrogatePK, Model): __tablename__ = 'projects' project_name = Column(db.Text(), unique=False, nullable=True, index=True) project_desc = Column(db.Text(), unique=False, nullable=True) start_date = Column(db.Date(), unique=False, nullable=False, index=True) end_date = Column(db.Date(), unique=False, nullable=True, index=True) members = relationship('User', secondary=project_user_map, backref=db.backref('user_projects', lazy='dynamic')) tasks = relationship('Task', backref='project_tasks') def __init__(self, *args, **kwargs): db.Model.__init__(self, *args, **kwargs) def __repr__(self): return '<Project(id={id}, project_name={project_name}, )>'.format( id=self.id, project_name=self.project_name)