def prepop_businesses(user): if user == None: user = get_default_user() reader = csv.reader(open(settings.BASE_DIR+'/prepop/businesses.csv', 'U'), delimiter=',', quotechar='"') i = 0 for row in reader: i+=1 if i == 1: continue name = row[0] addr = row[1] city = row[2] state = row[3] phurl = row[4] print('name: '+str(name)) print('addr: '+str(addr)) print('city: '+str(city)) print('state: '+str(state)) bset = Business.objects.filter(name=name,address=addr,state=state,city=city) if bset.count() == 0: b = Business(name=name.encode("utf8"), city=city.encode("utf8"), state=state, address=addr.encode("utf8"), lat=0, lon=0) b.save() elif bset.count() > 1: Business.objects.filter(name=name.encode("utf8"), city=city.encode("utf8"), state=state, address=addr.encode("utf8")).delete() b = Business(name=name.encode("utf8"), city=city.encode("utf8"), state=state, address=addr.encode("utf8"), lat=0, lon=0) b.save() else: b = bset[0] setBusLatLng(b) add_tag_to_bus(b, get_master_summary_tag(), get_default_user()) add_photo_by_url(phurl,b,user,default=True)
def create_business(name, address, state, city, lat, lon): bset = Business.objects.filter(name=name,address=address,state=state,city=city) if bset.count() > 0: return b = Business(name=name.encode("utf8"), city=city.encode("utf8"), state=state, address=address.encode("utf8"), lat=lat, lon=lon) b.save() setBusLatLng(b) add_tag_to_bus(b,get_master_summary_tag()) return b
def get_single_bus_data_ios(b, user): if b.lat == 0 or b.lon == 0: b = setBusLatLng(b) d = dict() d["businessID"] = b.id d["businessName"] = b.name d["businessCity"] = b.city d["businessState"] = b.state d["streetAddr"] = b.address d["latitude"] = b.lat d["longitude"] = b.lon d["businessID"] = b.id d["businessPhone"] = "555 555-5555" d["distanceFromCurrentUser"] = str(b.get_distance(user)) d["ratingOverAllUsers"] = round(getBusAvg(b.id) * 2) / 2 d["photo"] = get_photo_url(b) d["numberOfRatings"] = getNumRatings(b.id) d["numberOfLoves"] = getNumLoved(b) d["numberOfLikes"] = getNumLiked(b) # the user exists and has rated something if user and Rating.objects.filter(user=user, business=b).count() > 0: try: r = Rating.objects.get(user=user, business=b) except Rating.MultipleObjectsReturned: r = Rating.objects.filter(user=user, business=b)[0] d["ratingForCurrentUser"] = r.rating else: d["ratingForCurrentUser"] = 0 bustags = BusinessTag.objects.filter(business=b) # .exclude(tag=get_master_summary_tag()) d["categories"] = [] for bt in bustags: d["categories"].append(get_category_data(bt, user)) if d["ratingForCurrentUser"] == 0: # b.recommendation = get_best_current_recommendation(b, user) d["ratingRecommendation"] = getBusAvg(b.id) return d