From 214d8696fafee4e38c6bf039315aac37e4cd2e2b Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 21 Jul 2015 18:02:56 +0530 Subject: Add filters to question display --- testapp/exam/views.py | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'testapp/exam/views.py') diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 69d16d7..e1c9dc5 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -19,7 +19,8 @@ import json from testapp.exam.models import Quiz, Question, QuestionPaper, QuestionSet from testapp.exam.models import Profile, Answer, AnswerPaper, User, TestCase from testapp.exam.forms import UserRegisterForm, UserLoginForm, QuizForm,\ - QuestionForm, RandomQuestionForm, TestCaseFormSet + QuestionForm, RandomQuestionForm, TestCaseFormSet,\ + QuestionFilterForm from testapp.exam.xmlrpc_clients import code_server from settings import URL_ROOT from testapp.exam.models import AssignmentUpload @@ -1249,6 +1250,30 @@ def show_all_quiz(request): context_instance=ci) +@csrf_exempt +def ajax_questions_filter(request): + """Ajax call made when filtering displayed questions.""" + + filter_dict = {} + question_type = request.POST.get('question_type') + marks = request.POST.get('marks') + language = request.POST.get('language') + + if question_type != "select": + filter_dict['type'] = str(question_type) + + if marks != "": + filter_dict['points'] = marks + + if language != "select": + filter_dict['language'] = str(language) + + questions = list(Question.objects.filter(**filter_dict)) + + return my_render_to_response('exam/ajax_question_filter.html', + {'questions': questions}) + + def show_all_questions(request): """Show a list of all the questions currently in the databse.""" @@ -1261,18 +1286,24 @@ def show_all_questions(request): data = request.POST.getlist('question') if data is None: questions = Question.objects.all() + form = QuestionFilterForm() context = {'papers': [], 'question': None, - 'questions': questions} + 'questions': questions, + 'form': form + } return my_render_to_response('exam/showquestions.html', context, context_instance=ci) else: for i in data: question = Question.objects.get(id=i).delete() questions = Question.objects.all() + form = QuestionFilterForm() context = {'papers': [], 'question': None, - 'questions': questions} + 'questions': questions, + 'form': form + } return my_render_to_response('exam/showquestions.html', context, context_instance=ci) elif request.method == 'POST' and request.POST.get('edit') == 'edit': @@ -1312,9 +1343,12 @@ def show_all_questions(request): context_instance=ci) else: questions = Question.objects.all() + form = QuestionFilterForm() context = {'papers': [], 'question': None, - 'questions': questions} + 'questions': questions, + 'form': form + } return my_render_to_response('exam/showquestions.html', context, context_instance=ci) -- cgit From dbab99bc13b8483c24706e47a9a0926508e3c332 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 23 Jul 2015 16:32:13 +0530 Subject: Add filters: Minor fixes --- testapp/exam/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'testapp/exam/views.py') diff --git a/testapp/exam/views.py b/testapp/exam/views.py index e1c9dc5..f39f3c1 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -1262,7 +1262,7 @@ def ajax_questions_filter(request): if question_type != "select": filter_dict['type'] = str(question_type) - if marks != "": + if marks != "select": filter_dict['points'] = marks if language != "select": -- cgit