コード例 #1
0
ファイル: models.py プロジェクト: Detry322/hungry-casa
class Restaurant(db.Model):
    __tablename__ = 'restaurant'
    id = db.Column(db.Integer(), primary_key=True)
    grubhub_id = db.Column(db.String(20), unique=True, index=True)
    info = db.Column(db.Text(), nullable=False)
    menu = db.Column(db.Text(), nullable=False)

    def __init__(self, grubhub_id, info, menu):
        self.grubhub_id = grubhub_id
        if isinstance(info, str):
            self.info = info
        else:
            self.info = json.dumps(info)

        if isinstance(menu, str):
            self.menu = menu
        else:
            self.menu = json.dumps(menu)

    def info_json(self):
        info = json.loads(self.info)
        info['id'] = self.grubhub_id
        return info

    def menu_json(self):
        return json.loads(self.menu)
コード例 #2
0
class Rule(db.Model):
  __bind_key__ = 'wehomeproperty'
  id = db.Column(db.Integer(), index=True, primary_key=True)
  users = relationship("User", secondary=user_rule_association, back_populates="rules")
  api_id = db.Column(db.String(255))
  throttle_day = db.Column(db.String(255))
  throttle_hour = db.Column(db.String(255))
  throttle_min = db.Column(db.String(255))
  includes = db.Column(db.Text())
  excludes = db.Column(db.Text())
  statistics = db.Column(db.Boolean(), default=False)
  notes = db.Column(db.String(255))
  extra = db.Column(db.Text())
コード例 #3
0
class Event(db.Model):
    __tablename__ = "event"
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(255))
    description = db.Column(db.Text())
    verified = db.Column(db.Boolean)
    active = db.Column(db.Boolean)

    def __init__(self, name="", description=""):
        self.name = name
        self.description = description
        self.verified = False
        self.active = True

    def as_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'verified': self.verified,
            'active': self.active,
        }

    def update(self, values):
        for key, value in values.iteritems():
            self.__setattr__(key, value)

        try:
            db.session.add(self)
            db.session.commit()
            return self
        except IntegrityError:
            return None
コード例 #4
0
ファイル: models.py プロジェクト: a-woods1/capstone
class Product(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    product_name = db.Column(db.String(255))
    product_description = db.Column(db.Text())
    category_id = db.Column(db.Integer(),
                            db.ForeignKey('category.id'),
                            nullable=False)
    pre_approved = db.Column(db.Boolean())
コード例 #5
0
ファイル: models.py プロジェクト: Detry322/hungry-casa
class Order(db.Model):
    __tablename__ = 'order'
    id = db.Column(db.Integer(), primary_key=True)
    uuid = db.Column(db.String(40), unique=True, index=True)
    entries = db.relationship("Entry",
                              back_populates="order",
                              primaryjoin=(id == Entry.order_id))
    create_time = db.Column(db.DateTime, default=db.func.now())

    description = db.Column(db.Text(), nullable=False)
    closes_at = db.Column(db.Text(), nullable=False)

    restaurant_id = db.Column(db.Integer,
                              db.ForeignKey('restaurant.id'),
                              nullable=False)
    restaurant = db.relationship("Restaurant", foreign_keys=restaurant_id)

    def __init__(self, description, closes_at, restaurant):
        self.description = description
        self.closes_at = closes_at
        self.restaurant = restaurant
        self.uuid = str(uuid.uuid4())

    def json(self):
        return {
            'id': self.uuid,
            'description': self.description,
            'closes_at': self.closes_at,
            'restaurant_info': self.restaurant.info_json(),
            'orders': map(lambda entry: entry.json(), self.entries)
        }

    def user_json(self, user_uuid):
        entry = None
        for e in self.entries:
            if e.user_uuid == user_uuid:
                entry = e
        return {
            'id': self.uuid,
            'description': self.description,
            'closes_at': self.closes_at,
            'restaurant_info': self.restaurant.info_json(),
            'order': None if entry is None else entry.json(),
            'menu': self.restaurant.menu_json()
        }
コード例 #6
0
class UserSession(db.Model):
    __tablename__ = "user_session"
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer(), db.ForeignKey("user.id"))
    date = db.Column(db.Date())
    sets = db.relationship("UserSet")
    note = db.Column(db.Text())
    grip = db.Column(db.String(255))
    program = db.Column(db.Integer(), db.ForeignKey("program_template.id"))
コード例 #7
0
ファイル: models.py プロジェクト: a-woods1/capstone
class Request(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    person_id = db.Column(db.Integer(),
                          db.ForeignKey('person.id'),
                          nullable=False)
    product_id = db.Column(db.Integer(),
                           db.ForeignKey('product.id'),
                           nullable=False)
    request_justfication = db.Column(db.Text())
    request_date = db.Column(db.DateTime())
コード例 #8
0
ファイル: models.py プロジェクト: bopopescu/mvp
class Challenge(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(200), nullable=False)  # no empty names please
    desc = db.Column(
        db.Text(),
        nullable=False)  # we want to know what it is beyond a name too
    date_created = db.Column(db.DateTime(), nullable=False)
    preview_uri = db.Column(db.Text())  #preview URI
    listing_uri = db.Column(db.Text())  #listing URI

    creator_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=True)
    creator = db.relationship('User')  # who?

    def __init__(self, name, desc, preview_uri, listing_uri, creator):
        self.name = name
        self.desc = desc
        self.date_created = datetime.datetime.utcnow()
        self.preview_uri = preview_uri
        self.listing_uri = listing_uri
        self.creator = creator
コード例 #9
0
ファイル: models.py プロジェクト: bopopescu/mvp
class ChallengeMedia(db.Model):
    id = db.Column(db.Integer(), primary_key=True)

    challenge_id = db.Column(db.Integer,
                             db.ForeignKey("challenge.id"),
                             nullable=False)
    challenge = db.relationship('Challenge')

    uri = db.Column(db.Text(), nullable=False)  # Main URI
    tooltip = db.Column(
        db.Text(), nullable=True
    )  # in case you want to load up a tooltip / caption for the media
    priority = db.Column(
        db.Integer,
        nullable=False)  #1 for main, otherwise >1 for a "sort order"

    def __init__(self, challenge, uri, tooltip, priority):
        self.challenge = challenge
        self.uri = uri
        self.tooltip = tooltip
        self.priority = priority
コード例 #10
0
class Neighborhood(db.Model):
  __bind_key__ = 'wehomeproperty'
  id = db.Column(db.Integer(), index=True, primary_key=True)
  name = db.Column(db.String(255))
  region_id = db.Column(db.Integer(), index=True, unique=True)
  city = db.Column(db.String(255))
  state = db.Column(db.String(255))
  
  past_rent_ratio = db.Column(db.Float())
  past_increase_ratio = db.Column(db.Float())
  forecast_rent_ratio = db.Column(db.Float())
  forecast_increase_ratio = db.Column(db.Float())
  
  home_value_rent_price_history = db.Column(db.Text())
  home_value_sale_price_history = db.Column(db.Text())
  
  market_health_index = db.Column(db.Float())
  
  rent_final_point = db.Column(db.Float())
  zestimate = db.Column(db.Float())
  
  neighborhood_score = db.Column(db.Float())
  area_geoid = db.Column(db.Integer(), index=True)
  
  # for IRR
  hoa = db.Column(db.Float())
  property_tax = db.Column(db.Float())
  vaccancy_rate = db.Column(db.Float())
  property_management_fee = db.Column(db.Float())
  leasing_commission = db.Column(db.Float())
  insurance_cost = db.Column(db.Float())
  repair = db.Column(db.Float())
  cap_ex = db.Column(db.Float())
  acquisition_cost = db.Column(db.Float())
  disposition_cost = db.Column(db.Float())
  rent_growth = db.Column(db.Float())
  
  properties = db.Column(LONGTEXT())
  created_at = db.Column(db.DateTime(), default=datetime.datetime.now)
  updated_at = db.Column(db.DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now)
コード例 #11
0
class Area(db.Model):
  __bind_key__ = 'wehomeproperty'
  id = db.Column(db.Integer(), index=True, primary_key=True)
  geoid = db.Column(db.String(255), index=True, unique=True)
  cities = db.relationship('City', backref='area')
  name = db.Column(db.String(255), index=True)
  eng_name = db.Column(db.String(255), index=True)
  lat = db.Column(db.Float())
  lng = db.Column(db.Float())
  layer_type = db.Column(db.String(255), index=True)
  properties = db.Column(JSON())
  
  # for IRR
  property_tax = db.Column(db.Float())
  vaccancy_rate = db.Column(db.Float())
  property_management_fee = db.Column(db.Float())
  leasing_commission = db.Column(db.Float())
  insurance_cost = db.Column(db.Float())
  repair = db.Column(db.Float())
  cap_ex = db.Column(db.Float())
  acquisition_cost = db.Column(db.Float())
  disposition_cost = db.Column(db.Float())
  rent_growth = db.Column(db.Float())
  
  #
  down_payment = db.Column(db.Float())
  loan_interest_rate = db.Column(db.Float())
  expenses = db.Column(db.Float())
  closing_costs_misc = db.Column(db.Float())
  
  #
  history = db.Column(db.Text())
  block_villa_median = db.Column(db.Float())
  block_apartment_median = db.Column(db.Float())
  deal_average_price = db.Column(db.Float())
  list_average_price = db.Column(db.Float())
  occ_rate_long = db.Column(db.Float())
  occ_rate_airbnb = db.Column(db.Float())
  return_long = db.Column(db.Float())
  return_airbnb = db.Column(db.Float())
  
  created_at = db.Column(db.DateTime(), default=datetime.datetime.now)
  updated_at = db.Column(db.DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now)
コード例 #12
0
ファイル: models.py プロジェクト: Detry322/hungry-casa
class Entry(db.Model):
    __tablename__ = 'entry'
    id = db.Column(db.Integer(), primary_key=True)
    user_uuid = db.Column(db.String(40), nullable=False)
    order_id = db.Column(db.Integer, db.ForeignKey('order.id'), nullable=False)
    order = db.relationship("Order",
                            back_populates="entries",
                            foreign_keys=order_id)
    data = db.Column(db.Text(), nullable=False)

    def __init__(self, order, user_uuid, data):
        self.order = order
        self.user_uuid = user_uuid
        if isinstance(data, str):
            self.data = data
        else:
            self.data = json.dumps(data)

    def json(self):
        return json.loads(self.data)
コード例 #13
0
ファイル: models.py プロジェクト: bopopescu/mvp
class ChallengeInstanceMedia(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    data = db.Column(db.Text(), nullable=False)

    challenge_instance_id = db.Column(db.Integer(),
                                      db.ForeignKey("challenge_instance.id"),
                                      nullable=False)
    user_id = db.Column(db.Integer(), db.ForeignKey("user.id"), nullable=True)

    challenge_instance = db.relationship('ChallengeInstance')
    user = db.relationship('User')

    def __init__(self, challenge_instance, user, data):
        self.challenge_instance = challenge_instance
        self.user = user
        self.data = data

    @staticmethod
    def get_media(instance_id):
        challenge_instance_media = ChallengeInstanceMedia.query.filter_by(
            challenge_instance_id=instance_id)
        return ChallengeInstanceMediaSchema.dump(challenge_instance_media)