diff options
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index bdb86b9..03f4f61 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -868,7 +868,8 @@ def get_questions(paper): q_unanswered = paper.get_unanswered_questions() q_unanswered.sort() to_attempt = q_unanswered - for index, value in enumerate(all_questions, 1): + question = Question.objects.filter(id__in=all_questions) + for index, value in enumerate(question, 1): questions[value] = index questions = collections.OrderedDict(sorted(questions.items(), key=lambda x:x[1])) return questions, to_attempt, submitted @@ -928,6 +929,7 @@ def show_question(request, q_id, attempt_num, questionpaper_id, success_msg=None return complete(request, msg, attempt_num, questionpaper_id) else: return question(request, q_id, attempt_num, questionpaper_id, success_msg) + def _save_skipped_answer(old_skipped, user_answer, paper, question): @@ -1042,25 +1044,38 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): if time_left <= 0: reason = 'Your time is up!' return complete(request, reason, attempt_num, questionpaper_id) - # Display the same question if user_answer is None elif not user_answer: msg = "Please submit a valid option or code" time_left = paper.time_left() questions, to_attempt, submitted = get_questions(paper) - context = {'question': question, 'error_message': msg, - 'paper': paper, 'quiz_name': paper.question_paper.quiz.description, - 'time_left': time_left, 'questions': questions, - 'to_attempt': to_attempt, 'submitted': submitted} + context = {'question': question, 'paper': paper, + 'quiz_name': paper.question_paper.quiz.description, + 'time_left': time_left, 'questions': questions, + 'to_attempt': to_attempt, 'submitted': submitted, + 'error_message': msg} + ci = RequestContext(request) + + elif question.type == 'code' and user_answer: + msg = "Correct Output" + success = "True" + paper.completed_question(question.id) + time_left = paper.time_left() + questions, to_attempt, submitted = get_questions(paper) + context = {'question': question, 'paper': paper, + 'quiz_name': paper.question_paper.quiz.description, + 'time_left': time_left, 'questions': questions, + 'to_attempt': to_attempt, 'submitted': submitted, + 'error_message': msg, 'success': success} ci = RequestContext(request) - return my_render_to_response('yaksh/question.html', context, - context_instance=ci) else: next_q = paper.completed_question(question.id) return show_question(request, next_q, attempt_num, questionpaper_id, success_msg) + return my_render_to_response('yaksh/question.html', context, + context_instance=ci) def validate_answer(user, user_answer, question, json_data=None): """ @@ -1091,7 +1106,6 @@ def validate_answer(user, user_answer, question, json_data=None): result = json.loads(json_result) if result.get('success'): correct = True - return correct, result def get_question_labels(request, attempt_num=None, questionpaper_id=None): @@ -1536,7 +1550,6 @@ def show_all_questions(request): return my_render_to_response('yaksh/showquestions.html', context, context_instance=ci) - @login_required def user_data(request, username, questionpaper_id=None): """Render user data.""" |