Ejemplo n.º 1
0
class Price(db.Model):
    __tablename__ = 'prices'
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    property_id = db.Column(db.Integer,
                            db.ForeignKey('properties.id', ondelete='CASCADE'),
                            nullable=False)
    property = db.relationship(
        'Property',
        backref=backref('Price', uselist=False),
    )
    year = db.Column(db.Integer, nullable=False)
    amount = db.Column(db.Float, nullable=False)
    created_at = db.Column(db.DateTime(timezone=True), default=dt.now())
    updated_at = db.Column(db.DateTime(timezone=True),
                           default=dt.now(),
                           onupdate=dt.now())

    def __repr__(self):
        return f'{self.property} {self.year} rent({self.amount})\n'

    def __gt__(self, other):

        if (self.amount > other.amount):
            return True

        else:
            return False

    def __lt__(self, other):

        if (self.amount < other.amount):
            return True

        else:
            return False

    def __ge__(self, other):

        if (self.amount > other.amount or self.amount == other.amount):
            return True

        else:
            return False

    def __le__(self, other):

        if (self.amount < other.amount or self.amount == other.amount):
            return True

        else:
            return False

    def __add__(self, other):
        return self.amount + other.amount

    def json(self):
        return {
            'year': self.year,
            'amount': self.amount,
        }
Ejemplo n.º 2
0
class Report(db.Model):
    __tablename__ = 'reports'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255), )
    description = db.Column(db.Text, )
    date = db.Column(db.String(80), )
    file = db.Column(db.String(254))
    created_at = db.Column(db.DateTime(timezone=True), default=dt.now())
    updated_at = db.Column(db.DateTime(timezone=True),
                           default=dt.now(),
                           onupdate=dt.now())

    def __repr__(self):
        return f'{self.title} report'

    def json(self):
        return {
            'id': self.id,
            'title': self.title,
            'description': self.description,
            'file':
            f'https://res.cloudinary.com/kblinsurance/raw/upload/v1608312210/{self.file.decode("utf-8")}',
            'date': self.date,
            'created_at': self.created_at,
            'updated_at': self.updated_at,
        }
Ejemplo n.º 3
0
class Property(db.Model, Auth):
    __tablename__ = 'properties'
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    name = db.Column(db.String(255), nullable=False)
    type = db.Column(db.String(255), nullable=False)
    address = db.Column(db.String(255), nullable=False)
    area = db.Column(db.String(255), nullable=False)
    state = db.Column(db.String(255), nullable=False)
    bedrooms = db.Column(db.Integer, nullable=False)
    built = db.Column(db.Integer, nullable=True)
    units = db.Column(db.Integer, nullable=False)
    rents = db.relationship('Price',
                            cascade='all, delete, delete-orphan',
                            backref='properties',
                            lazy=False,
                            passive_deletes=True,
                            order_by='Price.year')
    serv_charge = db.Column(db.Float)
    sale_price = db.Column(db.Float)
    floors = db.Column(db.Integer)
    facilities = db.Column(db.Text(1024))
    land_size = db.Column(db.String(255))
    created_at = db.Column(db.DateTime(timezone=True), default=dt.now())
    updated_at = db.Column(db.DateTime(timezone=True),
                           default=dt.now(),
                           onupdate=dt.now())

    def __repr__(self):
        return f'{self.name} at {self.address}'

    def json(self):
        return {
            'id': self.id,
            'name': self.name,
            'address': self.address,
            'type': self.type,
            'area': self.area,
            'state': self.state,
            'bedrooms': self.bedrooms,
            'built': self.built,
            'units': self.units,
            'rents': self.rents,
            'serv_charge': self.serv_charge,
            'sale_price': self.sale_price,
            'floors': self.floors,
            'facilities': self.facilities,
            'land_size': self.land_size,
            'created_at': self.created_at,
            'updated_at': self.updated_at,
        }
Ejemplo n.º 4
0
class Role(db.Model):
    __tablename__ = 'roles'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(15), nullable=False)
    permissions = db.Column(db.String(255), db.Enum(Permissions), default=Permissions.READ, nullable=False)
    created_at = db.Column(db.DateTime(timezone=True), default=dt.now())
    updated_at = db.Column(db.DateTime(timezone=True), default=dt.now(), onupdate=dt.now())

    def __repr__(self):
        return '%r role' % self.title

    
    def json(self):
        return {
            'id': self.id,
            'role': self.title,
            'permissions': self.permissions,
        }
Ejemplo n.º 5
0
class User(db.Model, Auth):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    name = db.Column(db.String(120), nullable=False)
    phone = db.Column(db.String(14), nullable=True)
    password = db.Column(db.String(255), nullable=False)
    is_active = db.Column(db.Boolean(), default=False)
    created_at = db.Column(db.DateTime(timezone=True), default=dt.now())
    updated_at = db.Column(db.DateTime(timezone=True), default=dt.now(), onupdate=dt.now())


    def __repr__(self):
        return 'User %r' % self.username

    def get_id(self):
        return self.id

    # Required for administrative interface
    def __unicode__(self):
        return self.username
    
    def json(self):
        return {
            'id': self.id,
            'username': self.username,
            'name': self.name,
            'email': self.email,
            'phone': self.phone,
            'is_active': self.is_active,
            'created_at': self.created_at,
            'updated_at': self.updated_at,
        }

    def hashPassword(self, password):
        self.password = generate_password_hash(password)

    def checkPassword(self, password):
        return check_password_hash(self.password, password)
Ejemplo n.º 6
0
class ResetToken(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), unique=True, nullable=False)
    token = db.Column(db.String(255), nullable=False, default=token_urlsafe(16))
    created_at = db.Column(db.DateTime(timezone=True), default=dt.now())
    updated_at = db.Column(db.DateTime(timezone=True), default=dt.now(), onupdate=dt.now())

    def __repr__(self):
        return 'Reset token for %r' % self.email

    def updateToken(self):
        self.token = token_urlsafe(16)

    def get_token(self):
        return self.token
    
    def json(self):
        return {
            'email': self.email,
            'token': self.name,
            'created_at': self.created_at,
            'updated_at': self.updated_at,
        }