def post(self): postType = cgi.escape(self.request.get('createOrUpdate')) business_id = cgi.escape(self.request.get('business_id')) if postType == 'hide': self.__HideBusiness(business_id) else: business = Business() business.name = cgi.escape(self.request.get('name')) business.url = cgi.escape(self.request.get('url')) business.province = cgi.escape(self.request.get('province')) business.city = cgi.escape(self.request.get('city')) business.street = cgi.escape(self.request.get('street')) business.phonenumber = cgi.escape(self.request.get('phone')) hide = cgi.escape(self.request.get('hide')) if hide == 'True': business.hidden = True else: business.hidden = False if postType == 'update': business.business_id = business_id BusinessService().updateBusiness(business) else: BusinessService().saveBusiness(business); self.redirect('/businessservice/')
def buildBusinessDetailsFromJson(self, json): if 'id' in json: business = Business() business.business_id = self.formatYellowPagesId(json['id']) business.name = json['name'] if 'address' in json: if json['address']: address = json['address'] business.city = address['city'] business.province = address['prov'] business.country = 'Canada' business.street = address['street'] if 'geoCode' in json: if json['geoCode']: geolocation = json['geoCode'] lat = geolocation['latitude'] lon = geolocation['longitude'] business.geolocation = GeoLocation(lat, lon) if 'phones' in json: if json['phones']: phones = json['phones'] for phone in phones: if 'type' in phone: phoneType = phone['type'] if phoneType == 'primary': business.phonenumber = phone['dispNum'] if 'merchantUrl' in json: if json['merchantUrl']: url = json['merchantUrl'] business.url = url return business else: return None
def get(): result = None biz_dict = {} loc_dict = {} result = sql_adapter.fetchall(GET_ALL_QUERY) if result: for row in result: if row.id not in biz_dict.keys(): # biz is not in dict yet biz_dict[row.id] = Business( business_id=row.id, name=row.name, desc=row.description, price_level=row.price_level ) loc = Location( loc_id=row.loc_id, lat=row.lat, lon=row.lon, address=row.address, neighborhood=row.neighborhood, website=row.website, google_rating=row.google_rating, phone=row.phone, active=row.active, perm_closed=row.perm_closed ) biz_dict[row.id].add_location(loc) # lets build a location dict for the hours # for easy lookup if row.loc_id not in loc_dict: loc_dict[row.loc_id] = [] loc_dict[row.loc_id].append(Hours( weekday=row.weekday, open_time=row.open_time, close_time=row.close_time, hour_id=row.hour_id )) coup = Coupon( coupon_id=row.coupon_id, desc=row.coup_desc, restrictions=row.restrictions, coup_type=row.coup_type ) biz_dict[row.id].add_coupon(coup) for k,v in biz_dict.items(): for loc in v.locations: if loc.loc_id in loc_dict.keys(): loc.add_hours(loc_dict[loc.loc_id]) biz_list = [b.serialize() for b in biz_dict.values()] return jsonify(biz_list)
def update_biz(): result = {} try: req = request.json bus = Business( business_id=req.get('business_id'), name=req.get('name'), desc=req.get('desc'), price_level=req.get('price_level') ) bus.validate() bus = bus.serialize() sql_adapter.update(UPDATE_BUS_QUERY % bus) result['success'] = True except Exception as ex: print("Failed to update business object: %s" % ex) result['success'] = False result['error'] = str(ex) return jsonify(result)
def buildBusinessFromJson(self, json): businesses = [] if 'listings' in json: listings = json['listings'] for listing in listings: business = Business() business.business_id = self.formatYellowPagesId(listing['id']) business.name = listing['name'] if 'address' in listing: if listing['address']: address = listing['address'] business.city = address['city'] business.province = address['prov'] business.country = 'Canada' business.street = address['street'] if 'geoCode' in listing: if listing['geoCode']: geolocation = listing['geoCode'] lat = geolocation['latitude'] lon = geolocation['longitude'] business.geolocation = GeoLocation(lat, lon) businesses.append(business) return businesses
def convertDbBusinessToBusiness(self, dbBusiness): business = None if dbBusiness: business = Business() business.name = dbBusiness.name business.url = dbBusiness.url business.country = dbBusiness.country business.province = dbBusiness.province business.city = dbBusiness.city business.street = dbBusiness.street business.postalcode = dbBusiness.postalcode business.phonenumber = dbBusiness.phonenumber if dbBusiness.hidden != None: business.hidden = dbBusiness.hidden business.geolocation = self.convertGeoPTToGeoLocation(dbBusiness.location) business.business_id = str(dbBusiness.key().id()) return business