diff options
author | mahesh | 2017-08-30 18:46:49 +0530 |
---|---|---|
committer | mahesh | 2017-08-30 18:46:49 +0530 |
commit | e5cd812e8627686b2cff39ff14dbd9602f6fe3f3 (patch) | |
tree | 44c965ae5a116211f6b8230ebe7379050de34ead /yaksh/views.py | |
parent | 67ac8617f28cf3c5443e7af9593d0d912928612c (diff) | |
download | online_test-e5cd812e8627686b2cff39ff14dbd9602f6fe3f3.tar.gz online_test-e5cd812e8627686b2cff39ff14dbd9602f6fe3f3.tar.bz2 online_test-e5cd812e8627686b2cff39ff14dbd9602f6fe3f3.zip |
Fixes Multiple answerpaper objects returned bug
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 23 |
1 files changed, 17 insertions, 6 deletions
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 |