def get_venue_from_google(data): name = data.get("geo_venue") street = data.get("geo_street") street_number = data.get("geo_street_number") city = City.objects.filter( Q(name_std=data.get("geo_city").encode('utf8')) | Q(name=data.get("geo_city")) ) country = Country.objects.get(name='Canada') location = Point(( float(data.get("geo_longtitude")), float(data.get("geo_latitude")) )) if city.count() > 1: city = find_nearest_city(location, city) elif not city.count(): city = City.objects.distance(location).order_by('distance')[0] else: city = city[0] try: venue = Venue.objects.get(name=name, street=street, city=city, country=country, suggested=False) except: venue = Venue(name=name, street=street, city=city, country=country, location=location, suggested=False) venue.street_number = street_number venue.save() return venue
def save_venue(request): venue_identifier = request.POST["venue_identifier"] if venue_identifier: return Venue.objects.get(id=int(venue_identifier)) name = request.POST["venue_name"] street = request.POST["street"] location = Point(( float(request.POST["location_lng"]), float(request.POST["location_lat"]) )) if request.POST["city_identifier"]: city = City.objects.get(id=int(request.POST["city_identifier"])) else: cities = City.objects.filter( Q(name_std=request.POST["geo_city"].encode('utf8')) | Q(name=request.POST["geo_city"]) ) if cities.count() > 1: city = find_nearest_city(location, cities) elif not cities.count(): city = City.objects.distance(location).order_by('distance')[0] else: city = cities[0] country = Country.objects.get(name='Canada') venue, created = Venue.objects.get_or_create(name=name, street=street, city=city, country=country, location=location) return venue
def get_venue_from_google(data): name = data.get("geo_venue") street = data.get("geo_street") street_number = data.get("geo_street_number") city = City.objects.filter( Q(name_std=data.get("geo_city").encode('utf8')) | Q(name=data.get("geo_city"))) country = Country.objects.get(name='Canada') location = Point( (float(data.get("geo_longtitude")), float(data.get("geo_latitude")))) if city.count() > 1: city = find_nearest_city(location, city) elif not city.count(): city = City.objects.distance(location).order_by('distance')[0] else: city = city[0] try: venue = Venue.objects.get(name=name, street=street, city=city, country=country, suggested=False) except: venue = Venue(name=name, street=street, city=city, country=country, location=location, suggested=False) venue.street_number = street_number venue.save() return venue
def city(self): if self.lat_lon: return find_nearest_city(Point(self.lat_lon[::-1])) else: return None
def canadian_region(self): if self.lat_lon: nearest_city = find_nearest_city(Point(self.lat_lon[::-1])) return nearest_city.region else: return None