From e5cd812e8627686b2cff39ff14dbd9602f6fe3f3 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 30 Aug 2017 18:46:49 +0530 Subject: Fixes Multiple answerpaper objects returned bug --- yaksh/views.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 3c33e50..9f70299 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -402,12 +402,23 @@ def start(request, questionpaper_id=None, attempt_num=None): return my_render_to_response('yaksh/intro.html', context, context_instance=ci) else: - ip = request.META['REMOTE_ADDR'] - if not hasattr(user, 'profile'): - msg = 'You do not have a profile and cannot take the quiz!' - raise Http404(msg) - new_paper = quest_paper.make_answerpaper(user, ip, attempt_num) - return show_question(request, new_paper.current_question(), new_paper) + attempted_paper = AnswerPaper.objects.filter(user=user, + question_paper=quest_paper, + attempt_number=attempt_num + ) + if not attempted_paper: + ip = request.META['REMOTE_ADDR'] + if not hasattr(user, 'profile'): + msg = 'You do not have a profile and cannot take the quiz!' + raise Http404(msg) + new_paper = quest_paper.make_answerpaper(user, ip, attempt_num) + return show_question(request, new_paper.current_question(), + new_paper + ) + else: + msg = 'You have already finished the quiz!' + raise Http404(msg) + @login_required -- cgit