From: Seth Woodworth Date: Wed, 30 Jan 2013 00:39:51 +0000 (-0500) Subject: fixing school autocomplete for add course box X-Git-Tag: release-20150131~531^2~6 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=476c674bc24de822e13357fe3a650476b0edb296;p=oweals%2Fkarmaworld.git fixing school autocomplete for add course box --- diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index 5172bb5..d35ede7 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -4,6 +4,7 @@ import json +from django.http import HttpResponse from django.views.generic import DetailView from django.views.generic import TemplateView @@ -31,12 +32,14 @@ class AboutView(TemplateView): def school_list(request): """ Return JSON describing Schools that match q query on name """ - if request.method == 'GET' and request.is_ajax() \ - and request.GET.has_key('q'): + if request.method == 'POST' and request.is_ajax() \ + and request.POST.has_key('q'): # if an ajax get request with a 'q' name query - # get the list of schools that match and return - schools = School.objects.filter(name__icontains=request.GET['q'])[:4] - return json.dump({'status':'success', 'schools': schools}) + # 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]] + # return as json + return HttpResponse(json.dumps({'status':'success', 'schools': schools}), mimetype="application/json") else: # else return that the api call failed - return json.dump({'status':'fail'}) + return HttpResponse(json.dump({'status':'fail'}), mimetype="application/json") diff --git a/karmaworld/templates/lightbox/add_course.html b/karmaworld/templates/lightbox/add_course.html index dcfae1c..8a5a712 100644 --- a/karmaworld/templates/lightbox/add_course.html +++ b/karmaworld/templates/lightbox/add_course.html @@ -1,16 +1,32 @@ {% load url from future %} @@ -46,7 +68,8 @@ School diff --git a/karmaworld/urls.py b/karmaworld/urls.py index 49a2861..c100163 100644 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@ -45,7 +45,7 @@ urlpatterns = patterns('', # uploading files url(r'^ajax-upload$', ajax_uploader, name='ajax_upload'), # return json list of schools - url(r'^j/school/list$', school_list, name='json_school_list'), + url(r'^school/list/$', school_list, name='json_school_list'), # ---- end JSON views ----# url(r'^$', ListView.as_view(model=Course), name='home'),