route alias filter for checking exact number
This commit is contained in:
parent
def02ca104
commit
6f3136405d
|
@ -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
|
from django.contrib.auth.decorators import login_required
|
||||||
import json
|
import json
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
import re
|
||||||
|
|
||||||
def route(request, slug):
|
def route(request, slug):
|
||||||
srid = int(request.GET.get("srid", 4326))
|
srid = int(request.GET.get("srid", 4326))
|
||||||
|
@ -29,12 +30,26 @@ def area(request, slug):
|
||||||
})
|
})
|
||||||
|
|
||||||
def routes(request):
|
def routes(request):
|
||||||
|
|
||||||
q = request.GET.get("q", "")
|
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)
|
qset = Route.objects.filter(alias__icontains=q)
|
||||||
|
for route in qset:
|
||||||
|
if re.match(out_regex, route.alias):
|
||||||
|
ret.append(route.alias)
|
||||||
else:
|
else:
|
||||||
qset = Route.objects.all()
|
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)
|
return render_to_json_response(routes)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user