return geojson from stops

This commit is contained in:
Sanj 2012-02-19 18:52:34 +05:30
parent df16e4cfe5
commit de01b12eed
2 changed files with 32 additions and 0 deletions

View File

@ -4,4 +4,7 @@ import apiviews
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^route/(?P<slug>.*)$', apiviews.route), #FIXME: better regexp for route alias? (r'^route/(?P<slug>.*)$', apiviews.route), #FIXME: better regexp for route alias?
(r'^stop/(?P<slug>.*)$', apiviews.stop), (r'^stop/(?P<slug>.*)$', apiviews.stop),
(r'^routes/$', apiviews.routes),
(r'^areas/$', apiviews.areas),
(r'^stops/$', apiviews.stops),
) )

View File

@ -15,6 +15,35 @@ def route(request, slug):
}) })
def routes(request):
qset = Route.objects.all()
if request.GET.has_key('q'):
q = request.GET.get('q', '')
qset = qset.filter(alias__icontains=q) #FIXME: make a better Q object
routes = [route.alias for route in qset]
return render_to_json_response(routes)
def areas(request):
qset = Area.objects.all()
if request.GET.has_key('q'):
q = request.GET.get('q', '')
qset = qset.filter(display_name__icontains=q)
areas = [area.slug for area in qset]
return render_to_json_response(areas)
def stops(request):
qset = Stop.objects.all()
if request.GET.has_key('q'):
q = request.GET.get('q', '')
qset = qset.filter(display_name__icontains=q) #FIXME: This definitely needs to be a Q object with OR lookups for area name, road name, etc.
return render_to_json_response({
'type': 'FeatureCollection',
'features': [stop.get_geojson() for stop in qset]
})
def stop(request, slug): def stop(request, slug):
if request.POST: if request.POST:
if not slug: if not slug: