class Screen(SurrogatePK, Model): """Board of a user""" __tablename__ = 'screens' gare_depart = Column(db.Integer(), unique=False, nullable=False) gare_arrive = Column(db.Integer(), unique=False, nullable=False) titre_affichage = Column(db.String(18), unique=False, nullable=False) type_transport = Column(db.String(10), unique=False, nullable=False) board_id = reference_col('boards', nullable=False) board = relationship('Board', backref='screens') def __init__(self, board_id, gare_depart, gare_arrive, titre_affichage, type_transport, **kwargs): """Create instance.""" db.Model.__init__(self, board_id=board_id, gare_depart=gare_depart, gare_arrive=gare_arrive, titre_affichage=titre_affichage, type_transport=type_transport, **kwargs) def __repr__(self): """Represent instance as a unique string.""" return '<Screen({id})>'.format(id=self.board_id)
class Board(SurrogatePK, Model): """Board of a user""" __tablename__ = 'boards' name = Column(db.String(80), nullable=False) chip_id = Column(db.String(80), nullable=False, unique=True) user_id = reference_col('users', nullable=False) user = relationship('User', backref='boards') def __init__(self, name, chip_id, user_id, **kwargs): """Create instance.""" db.Model.__init__(self, name=name, chip_id=chip_id, user_id=user_id, **kwargs) def __repr__(self): """Represent instance as a unique string.""" return "<Board({name})>".format(name=self.name)
class User(UserMixin, SurrogatePK, Model): """A user of the app.""" __tablename__ = 'users' username = Column(db.String(80), unique=True, nullable=False) email = Column(db.String(80), unique=True, nullable=False) #: The hashed password password = Column(db.Binary(128), nullable=True) created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow) first_name = Column(db.String(30), nullable=True) last_name = Column(db.String(30), nullable=True) active = Column(db.Boolean(), default=False) is_admin = Column(db.Boolean(), default=False) def __init__(self, username, email, password=None, **kwargs): """Create instance.""" db.Model.__init__(self, username=username, email=email, **kwargs) if password: self.set_password(password) else: self.password = None def set_password(self, password): """Set password.""" self.password = bcrypt.generate_password_hash(password) def check_password(self, value): """Check password.""" return bcrypt.check_password_hash(self.password, value) @property def full_name(self): """Full user name.""" return '{0} {1}'.format(self.first_name, self.last_name) def __repr__(self): """Represent instance as a unique string.""" return '<User({username!r})>'.format(username=self.username)
class StationTransilien(SurrogatePK, Model): """Station de transilien""" __tablename__ = 'stations_transiliens' name = Column(db.String(80), unique=False, nullable=False) uic = Column(db.Integer(), unique=True, nullable=False) def __init__(self, name, uic, **kwargs): """Create instance.""" db.Model.__init__(self, name=name, uic=uic, **kwargs) def __repr__(self): return 'Station {name} uic {uic} '.format(name=self.name, uic=self.uic)
class Role(SurrogatePK, Model): """A role for a user.""" __tablename__ = 'roles' name = Column(db.String(80), unique=True, nullable=False) user_id = reference_col('users', nullable=True) user = relationship('User', backref='roles') def __init__(self, name, **kwargs): """Create instance.""" db.Model.__init__(self, name=name, **kwargs) def __repr__(self): """Represent instance as a unique string.""" return '<Role({name})>'.format(name=self.name)