From e244cd285669d3de80a764d75eecbb46b6d3fd63 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 21 Mar 2018 12:00:27 +0530 Subject: Add condition to get quiz status if answerpaper is created --- yaksh/models.py | 16 ++++++++++++++++ yaksh/test_models.py | 11 ++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index f065190..ea4efce 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -366,6 +366,20 @@ class Quiz(models.Model): course=course, passed=False ).values_list("user", flat=True).distinct().count() + def get_answerpaper_status(self, user, course): + try: + qp = self.questionpaper_set.get().id + except QuestionPaper.DoesNotExist: + qp = None + ans_ppr = AnswerPaper.objects.filter( + user=user, course=course, question_paper=qp + ) + if ans_ppr.exists(): + status = "completed" + else: + status = "not attempted" + return status + def __str__(self): desc = self.description or 'Quiz' return '%s: on %s for %d minutes' % (desc, self.start_date_time, @@ -393,6 +407,8 @@ class LearningUnit(models.Model): if course_status.exists(): if self in course_status.first().completed_units.all(): state = "completed" + elif self.type == "quiz": + state = self.quiz.get_answerpaper_status(user, course) elif course_status.first().current_unit == self: state = "inprogress" return state diff --git a/yaksh/test_models.py b/yaksh/test_models.py index cd4279b..e406e53 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -209,10 +209,11 @@ class LearningModuleTestCases(unittest.TestCase): # Given module_status = 'not attempted' # When + self.learning_module.learning_unit.remove(self.learning_unit_two) status = self.learning_module.get_status(self.student, self.course) # Then self.assertEqual(status, module_status) - + self.learning_module.learning_unit.add(self.learning_unit_two) # Module in progress # Given @@ -706,6 +707,9 @@ class QuestionPaperTestCases(unittest.TestCase): self.trial_course = Course.objects.create_trial_course(self.user) self.trial_quiz = Quiz.objects.create_trial_quiz(self.user) + @classmethod + def tearDownClass(self): + self.quiz.questionpaper_set.all().delete() def test_get_question_bank(self): # Given @@ -991,9 +995,10 @@ class AnswerPaperTestCases(unittest.TestCase): self.server_pool = server_pool self.server_thread = t = Thread(target=server_pool.run) t.start() - + @classmethod def tearDownClass(self): + self.quiz.questionpaper_set.all().delete() self.server_pool.stop() self.server_thread.join() settings.code_evaluators['python']['standardtestcase'] = \ @@ -1650,7 +1655,7 @@ class CourseTestCases(unittest.TestCase): name="test_course", creator=self.creator, enrollment="open") percent = self.course.percent_completed(self.student1) self.assertEqual(percent, 0) - + self.quiz1.questionpaper_set.all().delete() # for course with module but zero percent completed percent = self.course.percent_completed(self.student1) self.assertEqual(percent, 0) -- cgit From bd2672ea701fb3f6270a3e7af41cc44568f7330b Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 10 Apr 2018 17:54:49 +0530 Subject: Get answerpaper status for quiz completion --- yaksh/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index b13e19c..ecf7035 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -390,9 +390,9 @@ class Quiz(models.Model): qp = None ans_ppr = AnswerPaper.objects.filter( user=user, course=course, question_paper=qp - ) + ).order_by("-attempt_number") if ans_ppr.exists(): - status = "completed" + status = ans_ppr.first().status else: status = "not attempted" return status -- cgit