class Scenario(db.Model): __tablename__ = "scenario" __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text, nullable=False) state_code = db.Column(db.Enum(StateType)) project_id = db.Column(db.Integer, db.ForeignKey('project.id')) cycle_scenarios = db.relationship('CycleScenarios') cycle_cases = db.relationship('CycleCases') case = db.relationship('Case') def __init__(self, name, project_id): self.name = name self.project_id = project_id self.state_code = StateType.active
class User(db.Model): __tablename__ = "user" __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) email = db.Column(db.String(100), nullable=False, unique=True) password = db.Column(db.String(250), nullable=False) profile = db.Column(db.String(50), nullable=False) cycle_scenarios = db.relationship('CycleScenarios') project = db.relationship('Project') def __init__(self, name, email, password, profile='user'): self.name = name self.email = email self.password = User.generate_hash_password(password) self.profile = profile def verify_password(self, password): password = password.encode('utf-8') self.password = self.password.encode('utf-8') if bcrypt.hashpw(password, self.password) == self.password: return True return False @staticmethod def generate_hash_password(password): return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()) def generate_auth_token(self, expiration=600): s = Serializer(secretkey, expires_in=expiration) return s.dumps({'id': self.id}) @staticmethod def verify_auth_token(token): s = Serializer(secretkey) try: data = s.loads(token) except SignatureExpired: return None except BadSignature: return None g.user = User.query.get(data['id']) return g.user
class Project(db.Model): __tablename__ = "project" __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) owner_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) type_of_project = db.Column(db.String(50), nullable=False) privacy_policy = db.Column(db.String(50), nullable=False) scenario = db.relationship('Scenario') cycle = db.relationship('Cycle') def __init__(self, name, owner_id, type_of_project, privacy_policy): """Setting params to the object.""" self.name = name self.owner_id = owner_id self.type_of_project = type_of_project self.privacy_policy = privacy_policy def __repr__(self): """Representative Object Return.""" return '<Project %r>' % self.name
class Cycle(db.Model): __tablename__ = "cycle" __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) cycle = db.Column(db.Integer, nullable=False) name = db.Column(db.Text) project_id = db.Column(db.Integer, db.ForeignKey('project.id')) state_code = db.Column(db.Enum(StateType)) cycle_cases = db.relationship('CycleCases') cycle_scenarios = db.relationship('CycleScenarios') created_at = db.Column(db.DateTime, default=datetime.now) closed_at = db.Column(db.DateTime) closed_by = db.Column(db.Integer, db.ForeignKey('user.id')) closed_reason = db.Column(db.String(250)) last_change = db.Column(db.DateTime, default=datetime.now) def __init__(self, cycle, name, project_id): self.cycle = cycle self.name = name self.project_id = project_id self.state_code = StateType.active