예제 #1
0
파일: views.py 프로젝트: eknuth/pimh
def get_nearby_stops(request):
    if request.GET.get('coords', ''):
        form = SearchForm(request.GET)
        if form.is_valid():
            (lat,lon) = form.cleaned_data['coords'].split(',')
            
    elif request.GET.get('neighborhood', ''):
        if form.is_valid():
            (lat,lon) = form.cleaned_data['coords']
    search_point = Point(float(lat),float(lon))
    stops = BusStop.objects.distance(search_point).filter(geom__distance_lte=(search_point, distance(mi=.5))).order_by('distance')
    routes={}
    nearby_stops=[]
    for stop in stops:
        if not routes.has_key("%s_%s" % (stop.route, stop.dir)):
            r = BusLine.objects.get(route=stop.route, dir=stop.dir)
            stop.dir_desc = r.dir_desc
            routes["%s_%s" % (stop.route, stop.dir)]=True
            nearby_stops.append(stop)
    return render_to_response('_transit_get_stops.html', {
            'stops': nearby_stops
            })
예제 #2
0
파일: views.py 프로젝트: eknuth/pimh
def local_search(request, place_type):
    if request.GET.get('coords', ''):
        form = SearchForm(request.GET)
        if form.is_valid():
            (lat,lon) = form.cleaned_data['coords'].split(',')
            search_point = Point(float(lat),float(lon))
            r = Request(point=search_point, place_type=place_type)
            r.save()
            places = Place.objects.distance(search_point).filter(place_type=place_type).filter(point__distance_lte=(search_point, distance(mi=2))).order_by('distance')
            return render_to_response('_local_search.html', {
                    'title': place_type,
                    'places': places
                })

    else:
        form = SearchForm()
        return render_to_response('search.html', {
                'form': form,
                })