change stop requests to slugs instead of ids

This commit is contained in:
Sanj 2012-02-19 18:41:19 +05:30
parent 48580ad4be
commit df16e4cfe5
2 changed files with 8 additions and 8 deletions

View File

@ -2,6 +2,6 @@ from django.conf.urls.defaults import *
import apiviews
urlpatterns = patterns('',
(r'^route/(?P<alias>.*)$', apiviews.route), #FIXME: better regexp for route alias?
(r'^stop/(?P<id>[0-9]*)$', apiviews.stop),
(r'^route/(?P<slug>.*)$', apiviews.route), #FIXME: better regexp for route alias?
(r'^stop/(?P<slug>.*)$', apiviews.stop),
)

View File

@ -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
def route(request, alias):
route = get_object_or_404_json(Route, alias=alias)
def route(request, slug):
route = get_object_or_404_json(Route, slug=slug)
stops = [r.stop.get_geojson() for r in RouteDetail.objects.filter(route=route)]
return render_to_json_response({
'route': route.get_dict(),
@ -15,13 +15,13 @@ def route(request, alias):
})
def stop(request, id):
def stop(request, slug):
if request.POST:
if not id:
if not slug:
stop = Stop() #FIXME: should this return an error instead?
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))
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.