From df16e4cfe5b5deb5f4564231b8c556b52287fcde Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Feb 2012 18:41:19 +0530 Subject: [PATCH] change stop requests to slugs instead of ids --- chaloBEST/mumbai/apiurls.py | 4 ++-- chaloBEST/mumbai/apiviews.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/chaloBEST/mumbai/apiurls.py b/chaloBEST/mumbai/apiurls.py index 7360b4e..19781c2 100644 --- a/chaloBEST/mumbai/apiurls.py +++ b/chaloBEST/mumbai/apiurls.py @@ -2,6 +2,6 @@ from django.conf.urls.defaults import * import apiviews urlpatterns = patterns('', - (r'^route/(?P.*)$', apiviews.route), #FIXME: better regexp for route alias? - (r'^stop/(?P[0-9]*)$', apiviews.stop), + (r'^route/(?P.*)$', apiviews.route), #FIXME: better regexp for route alias? + (r'^stop/(?P.*)$', apiviews.stop), ) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 9e589f1..f02a1ba 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -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.