From ce21ae0cf3ea3541d588b30c0ae1c56d64c82e1d Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Thu, 31 Aug 2017 16:56:49 +0530 Subject: User Cannot skip/jump attempt numbers. Forces incremental nature of attempt number. --- yaksh/models.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 979740d..591f0e4 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -855,21 +855,28 @@ 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) + ans_paper = AnswerPaper.objects.filter(user=user, + attempt_number=attempt_num, + question_paper=self + ).order_by['-id'] + if ans_paper: + ans_paper = ans_paper[0] + else: + 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) return ans_paper def _is_questionpaper_passed(self, user): -- cgit From ef1e14e19f8bf0c1f075253a71ead98742b3f4d8 Mon Sep 17 00:00:00 2001 From: mahesh Date: Fri, 1 Sep 2017 15:55:15 +0530 Subject: Adds test case to check if multiple answerpapers for same arguments are not created. --- yaksh/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 591f0e4..56cced8 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -858,7 +858,7 @@ class QuestionPaper(models.Model): ans_paper = AnswerPaper.objects.filter(user=user, attempt_number=attempt_num, question_paper=self - ).order_by['-id'] + ).order_by('-id') if ans_paper: ans_paper = ans_paper[0] else: -- cgit