From 6f3136405d948a394b241c342c8c71d7c9a935c2 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 29 Feb 2012 01:49:03 +0530 Subject: [PATCH] route alias filter for checking exact number --- chaloBEST/mumbai/apiviews.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index 0106e04..55370a7 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -3,6 +3,7 @@ from ox.django.shortcuts import get_object_or_404_json, render_to_json_response from django.contrib.auth.decorators import login_required import json from django.views.decorators.csrf import csrf_exempt +import re def route(request, slug): srid = int(request.GET.get("srid", 4326)) @@ -29,12 +30,26 @@ def area(request, slug): }) def routes(request): + q = request.GET.get("q", "") - if q != '': + in_regex = re.compile(r'(\d{1,3})') + match = re.findall(route_regex, q) + if match: + route_no = match[0] + else: + route_no = '' + ret = [] + if route_no != '': + out_regex = re.compile(r'.*(\D|\A)%s(\D|\Z).*' % route_no) qset = Route.objects.filter(alias__icontains=q) + for route in qset: + if re.match(out_regex, route.alias): + ret.append(route.alias) else: qset = Route.objects.all() - routes = [route.alias for route in qset] + for route in qset: + ret.append(route.alias) +# routes = [route.alias for route in qset] return render_to_json_response(routes)