def shop_local(request): """ Return the shops near some location """ from shops.models import Shop from geopy import geocoders from distance_helper import distance_between_points in_range = [] params = {} params['states'] = STATE_CHOICES if request.method == "POST": max_distance = float(request.POST.get("max_distance")) metric = request.POST.get("metric", "miles") city = request.POST.get("city") state = request.POST.get("state") country = request.POST.get("country", "US") try: g = geocoders.Google(settings.GOOGLE_KEY) place = "%s, %s, %s" % (city, state, country) place, point1 = g.geocode(place) except Exception, e: logging.critical(e) request.flash['message'] = "Invalid input!" request.flash['severity'] = "error" return render_to_response( "%s/buy/shop_local.html" % request.marketplace.template_prefix, {'shops': in_range}, RequestContext(request)) marketplace = request.marketplace shops = Shop.actives.filter(marketplace=marketplace) for shop in shops: point2 = [float(x) for x in shop.geo_location()] distance = distance_between_points(point1, point2, metric) logging.critical("%s - %s - %s" % (shop, point2, distance)) if distance < max_distance: bisect.insort(in_range, (int(distance), shop)) params.update({ 'shops': in_range, 'metric': metric, 'selected_city': city, 'selected_state': state, 'do_search': True })
def shop_local(request): """ Return the shops near some location """ from shops.models import Shop from geopy import geocoders from distance_helper import distance_between_points in_range = [] params = {} params['states'] = STATE_CHOICES if request.method == "POST": max_distance = float(request.POST.get("max_distance")) metric = request.POST.get("metric", "miles") city = request.POST.get("city") state = request.POST.get("state") country = request.POST.get("country", "US") try: g = geocoders.Google(settings.GOOGLE_KEY) place = "%s, %s, %s" % (city, state, country) place, point1 = g.geocode(place) except Exception, e: logging.critical(e) request.flash['message'] = "Invalid input!" request.flash['severity'] = "error" return render_to_response("%s/buy/shop_local.html" % request.marketplace.template_prefix, {'shops' : in_range} , RequestContext(request)) marketplace = request.marketplace shops = Shop.actives.filter(marketplace=marketplace) for shop in shops: point2 = [float(x) for x in shop.geo_location()] distance = distance_between_points(point1, point2 , metric) logging.critical("%s - %s - %s" % (shop, point2, distance)) if distance < max_distance: bisect.insort(in_range, (int(distance), shop)) params.update({'shops': in_range, 'metric' : metric, 'selected_city': city, 'selected_state': state, 'do_search': True})
request.flash[ 'message'] = "Could not determine your location. Try again with other input data!" request.flash['severity'] = "error" return HttpResponseRedirect(reverse("buy_show_listing")) all_shows = Show.objects.filter(marketplace=marketplace).filter( date_to__gte=datetime.datetime.today()) max_distance = 1500 metric = "miles" shows = [] for show in all_shows: point2 = [float(x) for x in show.geo_location()] distance = distance_between_points(point1, point2, metric) if distance < max_distance: bisect.insort(shows, (int(distance), show)) params = {'states': STATE_CHOICES, 'shows': shows, 'place': place} return render_to_response( "%s/buy/show_listing.html" % request.marketplace.template_prefix, params, RequestContext(request)) def shop_local(request): """ Return the shops near some location """ from shops.models import Shop from geopy import geocoders
place, point1 = g.geocode(place) except Exception, e: request.flash['message'] = "Could not determine your location. Try again with other input data!" request.flash['severity'] = "error" return HttpResponseRedirect(reverse("buy_show_listing")) all_shows = Show.objects.filter(marketplace=marketplace).filter(date_to__gte=datetime.datetime.today()) max_distance = 1500 metric = "miles" shows = [] for show in all_shows: point2 = [float(x) for x in show.geo_location()] distance = distance_between_points(point1, point2 , metric) logging.critical("%s - %s - %s" % (show, point2, distance)) if distance < max_distance: bisect.insort(shows, (int(distance), show)) params = {'states': STATE_CHOICES, 'shows': shows, 'place': place } return render_to_response("%s/buy/show_listing.html" % request.marketplace.template_prefix, params, RequestContext(request)) def shop_local(request): """ Return the shops near some location """ from shops.models import Shop from geopy import geocoders