def notesOfCourse(request, course_pk): """ Ajax: Return all notes belonging to a course Used by search page javascript """ # If user id is sent with search, send moderation data per note # i.e: has a user voted on this note? if request.is_ajax(): if request.user.is_authenticated: user_pk = request.user.pk else: user_pk = -1 # Validate request parameters if not Course.objects.filter(pk=course_pk).exists(): raise Http404 response_json = [] #notes = Note.objects.get(school.pk=school_pk) course = Course.objects.get(pk=course_pk) print "notes request for course " + str(course.pk) + " by user " + str(user_pk) #print jsonifyModel(school, depth=2) response_json.append(jsonifyModel(course, depth=1, user_pk=user_pk)) #response_json.append(school_json) #print json.dumps(response_json) return HttpResponse(json.dumps(response_json), mimetype="application/json") else: raise Http404
def searchBySchool(request): """ Ajax: Return user's school's courses in JSON Used by search page javascript. If user has no school, show all schools """ response_json = [] if request.is_ajax(): if request.user.is_authenticated and request.user.get_profile().school is not None: school = get_object_or_404(School, pk=request.user.get_profile().school.pk) response_json.append(jsonifyModel(model=school, depth=1)) else: schools = School.objects.all() for school in schools: school_json = jsonifyModel(model=school, depth=1) response_json.append(school_json) #print 'searchBySchool: ' + str(response_json) return HttpResponse(json.dumps(response_json), mimetype="application/json") else: raise Http404