# -*- coding:utf8 -*-
# Copyright (C) 2012 FinalsClub Foundation
+import json
+
from django.views.generic import DetailView
from django.views.generic import TemplateView
context = { 'params': kwargs, \
'schools': School.objects.all()[:3] }
return context
+
+
+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 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})
+ else:
+ # else return that the api call failed
+ return json.dump({'status':'fail'})
from karmaworld.apps.courses.models import Course
from karmaworld.apps.courses.views import AboutView
from karmaworld.apps.courses.views import CourseDetailView
+from karmaworld.apps.courses.views import school_list
from karmaworld.apps.notes.views import NoteView
from karmaworld.apps.notes.views import raw_file
url(r'^(?P<school_slug>[^/]+)/(?P<course_slug>[^/]+)/(?P<slug>[^/]+)$', \
NoteView.as_view(), name='note_detail'),
- # uploading
- url(r'ajax-upload$', ajax_uploader, name='ajax_upload'),
+ # ---- JSON views ----#
+ # 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'),
+ # ---- end JSON views ----#
url(r'^$', ListView.as_view(model=Course), name='home'),
)