summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormahesh2018-01-29 13:00:02 +0530
committermahesh2018-01-30 15:00:37 +0530
commita4bf74684bcb32e461defc36e48ba71bf7f02c03 (patch)
tree9dc28778089ef293b46a20343fcff0cd59080ba9
parentb78b5d0b46114caefca35e82c502d1f7598e8e59 (diff)
downloadonline_test-a4bf74684bcb32e461defc36e48ba71bf7f02c03.tar.gz
online_test-a4bf74684bcb32e461defc36e48ba71bf7f02c03.tar.bz2
online_test-a4bf74684bcb32e461defc36e48ba71bf7f02c03.zip
Fix bug in make_answerpaper
-rw-r--r--yaksh/models.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 1e45851..4dd045a 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1161,7 +1161,7 @@ class QuestionPaper(models.Model):
return all_questions
def make_answerpaper(self, user, ip, attempt_num, course_id):
- """Creates an answer paper for the user to attempt the quiz"""
+ """Creates an answer paper for the user to attempt the quiz"""
try:
ans_paper = AnswerPaper.objects.get(user=user,
attempt_number=attempt_num,
@@ -1187,13 +1187,11 @@ class QuestionPaper(models.Model):
ans_paper.save()
ans_paper.questions_unanswered.add(*questions)
except AnswerPaper.MultipleObjectsReturned:
- ans_paper = AnswerPaper.objects.get(user=user,
- attempt_number=attempt_num,
- question_paper=self,
- course_id=course_id
- ).order_by('-id')
- ans_paper = ans_paper[0]
-
+ ans_paper = AnswerPaper.objects.filter(user=user,
+ attempt_number=attempt_num,
+ question_paper=self,
+ course_id=course_id
+ ).order_by('id').last()
return ans_paper
def _is_attempt_allowed(self, user, course_id):
@@ -1503,6 +1501,9 @@ class AnswerPaper(models.Model):
objects = AnswerPaperManager()
+ class Meta:
+ unique_together = ('user', 'question_paper', 'attempt_number')
+
def get_per_question_score(self, question_id):
if question_id not in self.get_questions().values_list('id', flat=True):
return 'NA'