Exemplo n.º 1
0
class SuperUser(db.Model):
    __tablename__ = 'super_user'
    __table_args__ = (db.UniqueConstraint('username'),
                      db.UniqueConstraint('password'))

    username = db.Column(db.String(100), primary_key=True)
    password = db.Column(db.String(200), nullable=False)

    def __repr__(self):
        return f'SuperUser(username={self.username})'
Exemplo n.º 2
0
class Rule(db.Model):
    __tablename__ = 'rule'
    __table_args = (db.UniqueConstraint('text', 'condominium_id'),
                    db.Index('rule_idx', 'text'))

    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(500), nullable=False)
    employee_id = db.Column(db.Integer,
                            db.ForeignKey('employee.id', ondelete='CASCADE'),
                            nullable=False)
    condominium_id = db.Column(db.Integer,
                               db.ForeignKey('condominium.id',
                                             ondelete='CASCADE'),
                               nullable=False)

    author = db.relationship('Employee',
                             backref=db.backref('rules',
                                                lazy=True,
                                                cascade='all, delete'),
                             lazy=False)

    condominium = db.relationship(
        'Condominium',
        backref=db.backref('rules', lazy=True, cascade='all, delete'),
        lazy=True,
        primaryjoin=
        'and_(Rule.condominium_id == Condominium.id, Condominium.active == 1)')

    def __repr__(self):
        return f'Rule(text={self.text})'
Exemplo n.º 3
0
class Guest(db.Model):
    __tablename__ = 'guest'
    __table_args__ = (db.UniqueConstraint('name', 'arrival', 'apartment_id'),
                      db.Index('guest_idx', 'name', 'arrival', 'apartment_id'))

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    arrival = db.Column(db.DateTime, nullable=False)
    active = db.Column(db.SmallInteger, default=1)
    apartment_id = db.Column(db.Integer,
                             db.ForeignKey('apartment.id', ondelete='CASCADE'),
                             nullable=False)

    apartment = db.relationship(
        'Apartment',
        backref=db.backref(
            'guests',
            lazy=True,
            cascade='all, delete',
            primaryjoin=
            'and_(Guest.apartment_id == Apartment.id, Guest.active == 1)'),
        lazy=True,
        primaryjoin=
        'and_(Guest.apartment_id == Apartment.id, Apartment.active == 1)')

    def __repr__(self):
        return f'Guest(id={self.id}, name={self.name}, arrival={self.arrival})'
Exemplo n.º 4
0
class Employee(db.Model):
    __tablename__ = 'employee'
    __table_args__ = (
        db.UniqueConstraint('cpf', 'role', 'condominium_id'),
        db.Index('employee_idx', 'cpf', 'role', 'condominium_id')
    )

    id = db.Column(db.Integer, primary_key=True)
    cpf = db.Column(db.String(11), nullable=False)
    name = db.Column(db.String(50), nullable=False)
    birthday = db.Column(db.Date, nullable=False)
    photo_location = db.Column(db.String(200), nullable=True, default='data/photos/default/employee.png')
    role = db.Column(db.String(50), nullable=False)
    type = db.Column(db.SmallInteger, nullable=False)
    condominium_id = db.Column(db.Integer, db.ForeignKey('condominium.id', ondelete='CASCADE'), nullable=False)
    active = db.Column(db.SmallInteger, default=1)

    condominium = db.relationship('Condominium',
                                  backref=db.backref('employees', lazy=True, cascade='all, delete'),
                                  lazy=True,
                                  primaryjoin='and_(Employee.condominium_id == Condominium.id, Condominium.active == 1)')

    def __repr__(self):
        return f'Employee(id={self.id}, ' \
            f'cpf={self.cpf}, ' \
            f'name={self.name}, ' \
            f'birthday={self.birthday}, ' \
            f'role={self.role})'
Exemplo n.º 5
0
class Resident(db.Model):
    __tablename__ = 'resident'
    __table_args__ = (db.UniqueConstraint('cpf', 'apartment_id'),
                      db.Index('resident_idx', 'cpf', 'apartment_id'))

    id = db.Column(db.Integer, primary_key=True)
    cpf = db.Column(db.String(11), nullable=False)
    name = db.Column(db.String(50), nullable=False)
    birthday = db.Column(db.Date, nullable=False)
    photo_location = db.Column(db.String(200),
                               nullable=True,
                               default='data/photos/default/resident.png')
    apartment_id = db.Column(db.Integer,
                             db.ForeignKey('apartment.id', ondelete='CASCADE'),
                             nullable=False)

    apartment = db.relationship(
        'Apartment',
        backref=db.backref('residents', lazy=True, cascade='all, delete'),
        lazy=True,
        primaryjoin=
        'and_(Resident.apartment_id == Apartment.id, Apartment.active == 1)')

    def __repr__(self):
        return f'Resident(id={self.id}, ' \
               f'name={self.name}, ' \
               f'birthday={self.birthday})'
Exemplo n.º 6
0
class Country(db.Model):
    __tablename__ = 'country'
    __table_args__ = (db.UniqueConstraint('name'), )

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40), nullable=False, index=True)

    def __repr__(self):
        return f'Country(id={self.id}, name={self.name})'
Exemplo n.º 7
0
class ResidentUser(db.Model):
    __tablename__ = 'resident_user'
    __table_args__ = (db.UniqueConstraint('apartment_id'),
                      db.UniqueConstraint('username'))

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100),
                         db.ForeignKey('username.username',
                                       ondelete='CASCADE'),
                         nullable=False)
    password = db.Column(db.String(200), nullable=False)
    apartment_id = db.Column(db.Integer,
                             db.ForeignKey('apartment.id', ondelete='CASCADE'),
                             nullable=False)

    apartment = db.relationship(
        'Apartment',
        backref=db.backref('user',
                           lazy=True,
                           cascade='all, delete',
                           uselist=False),
        lazy=True,
        uselist=False,
        primaryjoin=
        'and_(ResidentUser.apartment_id == Apartment.id, Apartment.active == 1)'
    )

    _username = db.relationship('Username',
                                backref=db.backref('resident_user',
                                                   lazy=True,
                                                   cascade='all, delete',
                                                   uselist=False),
                                lazy=True,
                                uselist=False)

    def __repr__(self):
        return f'ResidentUser(username={self.username})'
Exemplo n.º 8
0
class Address(db.Model):
    __tablename__ = 'address'
    __table_args__ = (db.UniqueConstraint('street_name', 'city_id'), db.Index('address_idx', 'street_name', 'city_id'))

    id = db.Column(db.Integer, primary_key=True)
    street_name = db.Column(db.String(150), nullable=False)
    neighbourhood = db.Column(db.String(150), nullable=False)
    city_id = db.Column(db.Integer, db.ForeignKey('city.id', ondelete='CASCADE'), nullable=False)

    city = db.relationship('City', backref=db.backref('addresses', lazy=True, cascade='all, delete'), lazy=False)

    def __repr__(self):
        return f'Address(id={self.id}, ' \
               f'street_name={self.street_name}, ' \
               f'neighbourhood={self.neighbourhood}, ' \
               f'city_name={self.city.name})'
Exemplo n.º 9
0
class Tower(db.Model):
    __tablename__ = 'tower'
    __table_args__ = (db.UniqueConstraint('name', 'condominium_id'), db.Index('tower_idx', 'name', 'condominium_id'))

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(10), nullable=False)
    condominium_id = db.Column(db.Integer, db.ForeignKey('condominium.id', ondelete='CASCADE'), nullable=False)
    active = db.Column(db.SmallInteger, default=1)

    condominium = db.relationship('Condominium',
                                  backref=db.backref('towers', lazy=True, cascade='all, delete'),
                                  lazy=True,
                                  primaryjoin='and_(Tower.condominium_id == Condominium.id, Condominium.active == 1)')

    def __repr__(self):
        return f'Tower(id={self.id}, ' \
               f'tower_name={self.name})'
Exemplo n.º 10
0
class Event(db.Model):
    __tablename__ = 'event'
    __table_args__ = (db.UniqueConstraint('event_type_id', 'start_datetime',
                                          'end_datetime'),
                      db.Index('event_idx', 'start_datetime', 'end_datetime'))

    id = db.Column(db.Integer, primary_key=True)
    start_datetime = db.Column(db.DateTime, nullable=False)
    end_datetime = db.Column(db.DateTime, nullable=False)
    active = db.Column(db.SmallInteger, default=1)
    event_type_id = db.Column(db.Integer,
                              db.ForeignKey('event_type.id',
                                            ondelete='CASCADE'),
                              nullable=False)
    apartment_id = db.Column(db.Integer,
                             db.ForeignKey('apartment.id', ondelete='CASCADE'),
                             nullable=False)

    apartment = db.relationship(
        'Apartment',
        backref=db.backref(
            'events',
            lazy=True,
            cascade='all, delete',
            primaryjoin=
            'and_(Event.apartment_id == Apartment.id, Event.active == 1)'),
        lazy=True,
        primaryjoin=
        'and_(Event.apartment_id == Apartment.id, Apartment.active == 1)')

    event_type = db.relationship(
        'EventType',
        backref=db.backref(
            'events',
            lazy=True,
            cascade='all, delete',
            primaryjoin=
            'and_(Event.event_type_id == EventType.id, Event.active == 1)'),
        lazy=False)

    def __repr__(self):
        return f'Event(id={self.id}, ' \
            f'start_datetime={self.start_datetime}, ' \
            f'end_datetime={self.end_datetime})'
Exemplo n.º 11
0
class State(db.Model):
    __tablename__ = 'state'
    __table_args__ = (db.UniqueConstraint('name', 'country_id'),
                      db.Index('state_idx', 'name', 'country_id'))

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), nullable=False)
    country_id = db.Column(db.Integer,
                           db.ForeignKey('country.id', ondelete='CASCADE'),
                           nullable=False)

    country = db.relationship('Country',
                              backref=db.backref('states',
                                                 lazy=True,
                                                 cascade='all, delete'),
                              lazy=True)

    def __repr__(self):
        return f'State(id={self.id}, name={self.name})'
Exemplo n.º 12
0
class Apartment(db.Model):
    __tablename__ = 'apartment'
    __table_args__ = (db.UniqueConstraint('apt_number', 'tower_id'),
                      db.Index('apt_idx', 'apt_number', 'tower_id'))

    id = db.Column(db.Integer, primary_key=True)
    apt_number = db.Column(db.Integer, nullable=False)
    tower_id = db.Column(db.Integer,
                         db.ForeignKey('tower.id', ondelete='CASCADE'),
                         nullable=False)
    active = db.Column(db.SmallInteger, default=1)

    tower = db.relationship(
        'Tower',
        backref=db.backref('apartments', lazy=True, cascade='all, delete'),
        lazy=True,
        primaryjoin='and_(Apartment.tower_id == Tower.id, Tower.active == 1)')

    def __repr__(self):
        return f'Apartment(id={self.id},' \
               f'apt_number={self.apt_number})'
Exemplo n.º 13
0
class EventType(db.Model):
    __tablename__ = 'event_type'
    __table_args__ = (db.UniqueConstraint('name', 'condominium_id'), )

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), nullable=False, index=True)
    condominium_id = db.Column(db.Integer,
                               db.ForeignKey('condominium.id',
                                             ondelete='CASCADE'),
                               nullable=False)

    condominium = db.relationship(
        'Condominium',
        backref=db.backref('event_types', lazy=True, cascade='all, delete'),
        lazy=True,
        primaryjoin=
        'and_(EventType.condominium_id == Condominium.id, Condominium.active == 1)'
    )

    def __repr__(self):
        return f'EventType(id={self.id}, name={self.name})'
Exemplo n.º 14
0
class Condominium(db.Model):
    __tablename__ = 'condominium'
    __table_args__ = (db.UniqueConstraint('street_number', 'address_id'), db.Index('cond_idx', 'street_number', 'address_id'))

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), nullable=False)
    street_number = db.Column(db.Integer, nullable=False)
    photo_location = db.Column(db.String(200), nullable=True, default='data/photos/default/condominium.png')
    address_id = db.Column(db.Integer, db.ForeignKey('address.id', ondelete='CASCADE'), nullable=False)
    active = db.Column(db.SmallInteger, default=1)

    address = db.relationship('Address',
                              backref=db.backref('condominiums',
                                                 lazy=True,
                                                 cascade='all, delete',
                                                 primaryjoin='and_(Address.id == Condominium.address_id, Condominium.active == 1)'),
                              lazy=True,
                              primaryjoin='and_(Condominium.address_id == Address.id, Condominium.active == 1)')

    def __repr__(self):
        return f'Condominium(id={self.id}, ' \
               f'condominium_name={self.name})'
Exemplo n.º 15
0
class Notification(db.Model):
    __tablename__ = 'notification'
    __table_args__ = (
        db.UniqueConstraint('title', 'condominium_id'),
        db.Index('date_idx', 'finish_date'),
        db.Index('notification_idx', 'title', 'condominium_id')
    )

    id = db.Column(db.Integer, primary_key=True)
    type = db.Column(db.Integer, nullable=False)
    title = db.Column(db.String(50), nullable=False)
    text = db.Column(db.String(300), nullable=False)
    finish_date = db.Column(db.Date, nullable=True)
    active = db.Column(db.SmallInteger, default=1)
    employee_id = db.Column(db.Integer, db.ForeignKey('employee.id', ondelete='CASCADE'), nullable=False)
    condominium_id = db.Column(db.Integer, db.ForeignKey('condominium.id', ondelete='CASCADE'), nullable=False)

    author = db.relationship('Employee',
                             backref=db.backref('notifications',
                                                lazy=True,
                                                cascade='all, delete',
                                                primaryjoin='and_(Notification.employee_id == Employee.id, Notification.active == 1)'),
                             lazy=True)

    condominium = db.relationship('Condominium',
                                  backref=db.backref('notifications',
                                                     lazy=True,
                                                     cascade='all, delete',
                                                     primaryjoin='and_(Notification.condominium_id == Condominium.id, Notification.active == 1)'),
                                  lazy=True,
                                  primaryjoin='and_(Notification.condominium_id == Condominium.id, Condominium.active == 1)')

    def __repr__(self):
        return f'Notification(id={self.id}, ' \
               f'type={self.type}, ' \
               f'title={self.title}, ' \
               f'text={self.text}, ' \
               f'finish_date={self.finish_date})'