Beispiel #1
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True)
    email = db.Column(db.String(120), index=True)
    pass

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    def __init__(self, username, email):
        self.username = username
        self.email = email

    def _toJson_(self):
        response = jsonify({
            'id': self.id,
            'username': self.username,
            'email': self.email,
        })
        return response
Beispiel #2
0
class User(db.Model):
    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(25), nullable=False)
    contact_number = db.Column(db.String(15), nullable=False)
    contact_email = db.Column(db.String(40), nullable=False)

    def __init__(self, name, contact_number, contact_email):
        self.name = name
        self.contact_number = contact_number
        self.contact_email = contact_email
Beispiel #3
0
class Favorite(db.Model):
    __tablename__ = "favorite"
    user_id = db.Column(db.Integer,
                        db.ForeignKey("user.id", ondelete="CASCADE"),
                        primary_key=True,
                        nullable=False)
    property_id = db.Column(db.Integer,
                            db.ForeignKey("property.id", ondelete="CASCADE"),
                            primary_key=True,
                            nullable=False)

    def __init__(self, user_id, property_id):
        self.user_id = user_id
        self.property_id = property_id
Beispiel #4
0
class DoorFrameType(db.Model):
    __tablename__ = "door_frame_type"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(25), nullable=False)
    glass_type = db.Column(db.Enum(GlassTypeEnum), nullable=False)
    screen = db.Column(db.Boolean, nullable=False)

    # Relationships
    properties = db.relationship("Property", backref="door_frame_type")

    def __init__(self, name, glass_type, screen):
        self.name = name
        self.glass_type = glass_type
        self.screen = screen
Beispiel #5
0
class PropertyAction(db.Model):
    __tablename__ = "property_action"
    property_id = db.Column(db.Integer,
                            db.ForeignKey("property.id", ondelete="CASCADE"),
                            primary_key=True)
    action = db.Column(db.Enum(PropertyActionEnum),
                       nullable=False,
                       primary_key=True)
    price = db.Column(db.Integer, nullable=False)

    def __init__(self, property_id, action, price):
        self.property_id = property_id
        self.action = action
        self.price = price
class PropertySupervisor(db.Model):
    __tablename__ = "property_supervisor"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(25), nullable=False)
    address = db.Column(db.String(40), nullable=True)
    contact_number = db.Column(db.String(15), nullable=False)
    contact_name = db.Column(db.String(25), nullable=False)
    contact_email = db.Column(db.String(40), nullable=False)
    website = db.Column(db.String(30), nullable=True)

    # Relationships
    properties = db.relationship("Property", backref="supervisor")
    commented_by = db.relationship("User",
                                   secondary="comment",
                                   backref=db.backref("comments",
                                                      lazy="dynamic"))

    def __init__(self, name, address, contact_number, contact_name,
                 contact_email, website):
        self.name = name
        self.address = address
        self.contact_number = contact_number
        self.contact_name = contact_name
        self.contact_email = contact_email
        self.website = website
Beispiel #7
0
class Comment(db.Model):
    __tablename__ = "comment"
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("user.id", ondelete="CASCADE"),
                        nullable=False)
    supervisor_id = db.Column(db.Integer,
                              db.ForeignKey("property_supervisor.id",
                                            ondelete="CASCADE"),
                              nullable=False)
    comment = db.Column(db.String(120), nullable=False)
    rating = db.Column(db.Integer, nullable=False)

    # Relationships.
    user = db.relationship("User", backref="comment")

    def __init__(self, user_id, supervisor_id, comment, rating):
        self.user_id = user_id
        self.supervisor_id = supervisor_id
        self.comment = comment
        self.rating = rating
Beispiel #8
0
class Visit(db.Model):
    __tablename__ = "visit"
    user_id = db.Column(db.Integer,
                        db.ForeignKey("user.id", ondelete="CASCADE"),
                        primary_key=True,
                        nullable=False)
    property_id = db.Column(db.Integer,
                            db.ForeignKey("property.id", ondelete="CASCADE"),
                            primary_key=True,
                            nullable=False)
    visit_date = db.Column(db.Date, nullable=False)
    status = db.Column(db.Enum(VisitStatusEnum), nullable=False)

    # Relationships.
    property = db.relationship("Property", backref="visit")

    def __init__(self, user_id, property_id, visit_date, status):
        self.user_id = user_id
        self.property_id = property_id
        self.visit_date = visit_date
        self.status = status
Beispiel #9
0
class City(db.Model):
    __tablename__ = "city"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(25), nullable=False)
    country_name = db.Column(db.String(25), nullable=False)
    population = db.Column(db.Integer, nullable=False)
    average_temp = db.Column(db.Numeric(3, 1), nullable=False)
    average_humidity = db.Column(db.Integer, nullable=False)
    average_precip = db.Column(db.Numeric(5, 1), nullable=False)

    # Relationships
    properties = db.relationship("Property", backref="city")

    def __init__(self, name, country_name, population, average_temp,
                 average_humidity, average_precip):
        self.name = name
        self.country_name = country_name
        self.population = population
        self.average_temp = average_temp
        self.average_humidity = average_humidity
        self.average_precip = average_precip
Beispiel #10
0
class Property(db.Model):
    __tablename__ = "property"
    id = db.Column(db.Integer, primary_key=True)
    floor = db.Column(db.Integer, nullable=False)
    postal_code = db.Column(db.String(10), nullable=False)
    street_address = db.Column(db.String(35), nullable=False)
    street_number = db.Column(db.Integer, nullable=True)
    property_type = db.Column(db.Enum(PropertyTypeEnum), nullable=False)
    size = db.Column(db.Integer, nullable=False)
    rooms = db.Column(db.Integer, nullable=True)
    longitude = db.Column(db.Numeric(8, 5), nullable=False)
    latitude = db.Column(db.Numeric(8, 5), nullable=False)
    energy_certificate = db.Column(db.Enum(EnergyCertificateEnum),
                                   nullable=True)
    city_id = db.Column(db.Integer, db.ForeignKey("city.id"), nullable=False)
    supervisor_id = db.Column(db.Integer,
                              db.ForeignKey("property_supervisor.id"),
                              nullable=False)
    heating_type_id = db.Column(db.Integer,
                                db.ForeignKey("heating_type.id"),
                                nullable=False)
    door_frame_id = db.Column(db.Integer,
                              db.ForeignKey("door_frame_type.id"),
                              nullable=False)
    details = db.Column(db.String(150), nullable=True)

    # Relationships
    actions = db.relationship("PropertyAction", backref="property")
    visitors = db.relationship("User",
                               secondary="visit",
                               backref=db.backref("visits", lazy="dynamic"))
    favored_by = db.relationship("User",
                                 secondary="favorite",
                                 backref=db.backref("properties",
                                                    lazy="dynamic"))

    def __init__(self, floor, postal_code, street_address, street_number,
                 property_type, size, rooms, longitude, latitude,
                 energy_certificate, city_id, supervisor_id, heating_type_id,
                 door_frame_id, details):
        self.floor = floor
        self.postal_code = postal_code
        self.street_address = street_address
        self.street_number = street_number
        self.property_type = property_type
        self.size = size
        self.rooms = rooms
        self.longitude = longitude
        self.latitude = latitude
        self.energy_certificate = energy_certificate
        self.city_id = city_id
        self.supervisor_id = supervisor_id
        self.heating_type_id = heating_type_id
        self.door_frame_id = door_frame_id
        self.details = details