diff options
author | ankitjavalkar | 2015-07-21 18:02:56 +0530 |
---|---|---|
committer | ankitjavalkar | 2015-08-05 12:00:54 +0530 |
commit | 214d8696fafee4e38c6bf039315aac37e4cd2e2b (patch) | |
tree | f7bc823ab005a9791f020c0eeb7a0a1f828b28fe /testapp/exam/views.py | |
parent | 0225aad1492600ed53504b0986fd13da24c28ae9 (diff) | |
download | online_test-214d8696fafee4e38c6bf039315aac37e4cd2e2b.tar.gz online_test-214d8696fafee4e38c6bf039315aac37e4cd2e2b.tar.bz2 online_test-214d8696fafee4e38c6bf039315aac37e4cd2e2b.zip |
Add filters to question display
Diffstat (limited to 'testapp/exam/views.py')
-rw-r--r-- | testapp/exam/views.py | 42 |
1 files changed, 38 insertions, 4 deletions
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) |