Ejemplo n.º 1
0
class Contact(db.Model):
    __tablename__ = 'contacts'
    __table_args__ = (UniqueConstraint('name', 'tel'), )

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), index=True)
    tel = db.Column(db.String(255), index=True)
    comment = db.Column(db.String(1024))
Ejemplo n.º 2
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(255), index=True, nullable=False)
    password = db.Column(db.String(1024), index=True, nullable=False)
    email = db.Column(db.String(255), unique=True, index=True, nullable=False)

    role = db.Column(db.String(50), index=True, nullable=False)
    status = db.Column(db.String(50),
                       index=True,
                       nullable=False,
                       default=STATUS_ACTIVE)

    created_at = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, index=True, default=datetime.utcnow)

    publisher_id = db.Column(db.Integer,
                             db.ForeignKey('publishers.id',
                                           ondelete='CASCADE'),
                             index=True)
    publisher = db.relationship(Publisher,
                                foreign_keys=[publisher_id],
                                uselist=False,
                                lazy='joined')

    @property
    def is_admin(self):
        return self.role == ROLE_ADMIN
Ejemplo n.º 3
0
class Location(db.Model):
    __tablename__ = 'locations'
    __table_args__ = (UniqueConstraint('address', 'city_id'), )

    id = db.Column(db.Integer, primary_key=True)
    address = db.Column(db.String(2048), index=True)

    city_id = db.Column(db.Integer,
                        db.ForeignKey('cities.id', ondelete='CASCADE'))
    city = db.relationship('City',
                           foreign_keys=[city_id],
                           uselist=False,
                           lazy='joined',
                           cascade="all, delete")
Ejemplo n.º 4
0
class DeviceHealth(db.Model):
    __tablename__ = 'devices_health'

    id = db.Column(db.Integer, primary_key=True)

    device_id = db.Column(db.Integer,
                          db.ForeignKey('devices.id', ondelete='CASCADE'),
                          index=True,
                          nullable=False)
    device = db.relationship('Device',
                             foreign_keys=[device_id],
                             uselist=False,
                             lazy='joined')

    software_version = db.Column(db.String(255), index=True, nullable=True)

    created_at = db.Column(db.DateTime, index=True, default=datetime.utcnow)
Ejemplo n.º 5
0
class File(db.Model):
    __tablename__ = 'files'

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(255), index=True)
    comment = db.Column(db.String(1024), index=True)
    src = db.Column(db.String(256))
    status = db.Column(db.String(50), index=True, nullable=False, default=STATUS_CREATED)

    created_by = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='SET NULL'))
    publisher_id = db.Column(db.Integer, db.ForeignKey('publishers.id', ondelete='CASCADE'), nullable=False, index=True)
    publisher = db.relationship(Publisher, foreign_keys=[publisher_id], uselist=False, lazy='joined')

    created_at = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, index=True, default=datetime.utcnow)
Ejemplo n.º 6
0
class Publisher(db.Model):
    __tablename__ = 'publishers'

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(255), unique=True, index=True, nullable=False)
    comment = db.Column(db.String(1024), index=True, nullable=True)
    airtime = db.Column(db.DECIMAL(precision=4, scale=1),
                        index=True,
                        nullable=True)

    created_by = db.Column(db.Integer,
                           db.ForeignKey('users.id', ondelete='SET NULL'))

    created_at = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, index=True, default=datetime.utcnow)
Ejemplo n.º 7
0
class Device(db.Model):
    __tablename__ = 'devices'

    id = db.Column(db.Integer, primary_key=True)

    comment = db.Column(db.String(1024), index=True)
    status = db.Column(db.String(50), index=True, default=UNAPPROVED)

    location_id = db.Column(db.Integer,
                            db.ForeignKey('locations.id', ondelete='CASCADE'))
    location = db.relationship(Location,
                               foreign_keys=[location_id],
                               uselist=False,
                               lazy='joined')

    contact_id = db.Column(db.Integer,
                           db.ForeignKey('contacts.id', ondelete='SET NULL'))
    contact = db.relationship('Contact',
                              foreign_keys=[contact_id],
                              uselist=False,
                              lazy='joined')

    # Health info multiple ref
    # Status history multiple ref

    access_token = db.Column(db.String(255),
                             index=True,
                             default=partial(get_random_str, 200),
                             nullable=False)
    uid_token = db.Column(db.String(255),
                          unique=True,
                          index=True,
                          nullable=False)

    created_at = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, index=True, default=datetime.utcnow)
Ejemplo n.º 8
0
class City(db.Model):
    __tablename__ = 'cities'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True, index=True)