From: Seth Woodworth Date: Wed, 26 Jun 2013 16:58:25 +0000 (-0400) Subject: modify the autocomplete ajax method to return School.alias matches before name matches X-Git-Tag: release-20150131~413 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=40b2cac714e3675614678c94c5fd9a214f1eb596;p=oweals%2Fkarmaworld.git modify the autocomplete ajax method to return School.alias matches before name matches --- diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index cc6fe00..ebad7b3 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -78,8 +78,12 @@ def school_list(request): and request.POST.has_key('q'): # if an ajax get request with a 'q' name query # get the schools as a id name dict, - schools = [{'id': s.id, 'name': s.name} for s in \ - School.objects.filter(name__icontains=request.POST['q'])[:4]] + _query = request.POST['q'] + matching_school_aliases = list(School.objects.filter(alias__icontains=_query)) + matching_school_names = list(School.objects.filter(name__icontains=_query)[:20]) + _schools = matching_school_aliases[:2] + matching_school_names + schools = [{'id': s.id, 'name': s.name} for s in _schools] + # return as json return HttpResponse(json.dumps({'status':'success', 'schools': schools}), mimetype="application/json") else: