change stop requests to slugs instead of ids
This commit is contained in:
parent
48580ad4be
commit
df16e4cfe5
|
@ -2,6 +2,6 @@ from django.conf.urls.defaults import *
|
||||||
import apiviews
|
import apiviews
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
(r'^route/(?P<alias>.*)$', apiviews.route), #FIXME: better regexp for route alias?
|
(r'^route/(?P<slug>.*)$', apiviews.route), #FIXME: better regexp for route alias?
|
||||||
(r'^stop/(?P<id>[0-9]*)$', apiviews.stop),
|
(r'^stop/(?P<slug>.*)$', apiviews.stop),
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,8 +3,8 @@ from ox.django.shortcuts import get_object_or_404_json, render_to_json_response
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
|
|
||||||
def route(request, alias):
|
def route(request, slug):
|
||||||
route = get_object_or_404_json(Route, alias=alias)
|
route = get_object_or_404_json(Route, slug=slug)
|
||||||
stops = [r.stop.get_geojson() for r in RouteDetail.objects.filter(route=route)]
|
stops = [r.stop.get_geojson() for r in RouteDetail.objects.filter(route=route)]
|
||||||
return render_to_json_response({
|
return render_to_json_response({
|
||||||
'route': route.get_dict(),
|
'route': route.get_dict(),
|
||||||
|
@ -15,13 +15,13 @@ def route(request, alias):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def stop(request, id):
|
def stop(request, slug):
|
||||||
if request.POST:
|
if request.POST:
|
||||||
if not id:
|
if not slug:
|
||||||
stop = Stop() #FIXME: should this return an error instead?
|
stop = Stop() #FIXME: should this return an error instead?
|
||||||
else:
|
else:
|
||||||
stop = get_object_or_404_json(Stop, id=id)
|
stop = get_object_or_404_json(Stop, slug=slug)
|
||||||
return render_to_json_response(stop.from_geojson(request.POST))
|
return render_to_json_response(stop.from_geojson(request.POST))
|
||||||
else:
|
else:
|
||||||
stop = get_object_or_404_json(Stop, id=id)
|
stop = get_object_or_404_json(Stop, slug=slug)
|
||||||
return render_to_json_response(stop.get_geojson()) #FIXME: please don't repeat this code, its retarded.
|
return render_to_json_response(stop.get_geojson()) #FIXME: please don't repeat this code, its retarded.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user