summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-09-05 18:40:44 +0530
committerGitHub2017-09-05 18:40:44 +0530
commite3a43662d2aae8688039671d3de532e48fbdfda9 (patch)
treec644e44b0cefa1c32e4ff02cfe6ed347dfe1e5df /yaksh/models.py
parent97a96d1678cb55b95ed14eb9a2b2790415d30abc (diff)
parent09931d64e05378143a9a1f2e634fc447f935d873 (diff)
downloadonline_test-e3a43662d2aae8688039671d3de532e48fbdfda9.tar.gz
online_test-e3a43662d2aae8688039671d3de532e48fbdfda9.tar.bz2
online_test-e3a43662d2aae8688039671d3de532e48fbdfda9.zip
Merge pull request #324 from maheshgudi/bugfix_multiple_answerpaper
Minor Bug fix (Anonymous User and Multiple Answerpaper errors)
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py43
1 files changed, 28 insertions, 15 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 979740d..063e1e3 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -855,21 +855,34 @@ class QuestionPaper(models.Model):
def make_answerpaper(self, user, ip, attempt_num):
"""Creates an answer paper for the user to attempt the quiz"""
- ans_paper = AnswerPaper(
- user=user,
- user_ip=ip,
- attempt_number=attempt_num
- )
- ans_paper.start_time = timezone.now()
- ans_paper.end_time = ans_paper.start_time + \
- timedelta(minutes=self.quiz.duration)
- ans_paper.question_paper = self
- ans_paper.save()
- questions = self._get_questions_for_answerpaper()
- for question in questions:
- ans_paper.questions.add(question)
- for question in questions:
- ans_paper.questions_unanswered.add(question)
+ try:
+ ans_paper = AnswerPaper.objects.get(user=user,
+ attempt_number=attempt_num,
+ question_paper=self
+ )
+ except AnswerPaper.DoesNotExist:
+ ans_paper = AnswerPaper(
+ user=user,
+ user_ip=ip,
+ attempt_number=attempt_num
+ )
+ ans_paper.start_time = timezone.now()
+ ans_paper.end_time = ans_paper.start_time + \
+ timedelta(minutes=self.quiz.duration)
+ ans_paper.question_paper = self
+ ans_paper.save()
+ questions = self._get_questions_for_answerpaper()
+ for question in questions:
+ ans_paper.questions.add(question)
+ for question in questions:
+ ans_paper.questions_unanswered.add(question)
+ except AnswerPaper.MultipleObjectsReturned:
+ ans_paper = AnswerPaper.objects.get(user=user,
+ attempt_number=attempt_num,
+ question_paper=self
+ ).order_by('-id')
+ ans_paper = ans_paper[0]
+
return ans_paper
def _is_questionpaper_passed(self, user):