From 5b43f7937526bb0351a10b5ffcdc7bcb5425e5d9 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 10 Jan 2018 15:05:02 +0530 Subject: - Change time_between_attempts field unit Hours - Fix bug causing exception when only a single quiz exists with no questionpaper --- yaksh/models.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index d4a73fa..fea8fda 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -78,7 +78,6 @@ string_check_type = ( attempts = [(i, i) for i in range(1, 6)] attempts.append((-1, 'Infinite')) -days_between_attempts = [(j, j) for j in range(401)] test_status = ( ('inprogress', 'Inprogress'), @@ -294,8 +293,8 @@ class Quiz(models.Model): # Number of attempts for the quiz attempts_allowed = models.IntegerField(default=1, choices=attempts) - time_between_attempts = models.IntegerField( - "Number of Days", choices=days_between_attempts + time_between_attempts = models.FloatField( + "Time Between Quiz Attempts in hours" ) is_trial = models.BooleanField(default=False) @@ -335,20 +334,32 @@ class Quiz(models.Model): return demo_quiz def get_total_students(self, course): + try: + qp = self.questionpaper_set.get().id + except QuestionPaper.DoesNotExist: + qp = None return AnswerPaper.objects.filter( - question_paper=self.questionpaper_set.get().id, + question_paper=qp, course=course ).values_list("user", flat=True).distinct().count() def get_passed_students(self, course): + try: + qp = self.questionpaper_set.get().id + except QuestionPaper.DoesNotExist: + qp = None return AnswerPaper.objects.filter( - question_paper=self.questionpaper_set.get().id, + question_paper=qp, course=course, passed=True ).values_list("user", flat=True).distinct().count() def get_failed_students(self, course): + try: + qp = self.questionpaper_set.get().id + except QuestionPaper.DoesNotExist: + qp = None return AnswerPaper.objects.filter( - question_paper=self.questionpaper_set.get().id, + question_paper=qp, course=course, passed=False ).values_list("user", flat=True).distinct().count() @@ -1181,7 +1192,7 @@ class QuestionPaper(models.Model): user=user, questionpaper=self, course_id=course_id ) if last_attempt: - time_lag = (timezone.now() - last_attempt.start_time).days + time_lag = (timezone.now() - last_attempt.start_time).total_seconds() / 3600 return time_lag >= self.quiz.time_between_attempts else: return True -- cgit From a4bf74684bcb32e461defc36e48ba71bf7f02c03 Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 29 Jan 2018 13:00:02 +0530 Subject: Fix bug in make_answerpaper --- yaksh/models.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'yaksh/models.py') 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' -- cgit From 782fd83b5931efde8ae26795c65e952df5012d0f Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 30 Jan 2018 15:02:55 +0530 Subject: Add test cases to check for duplicate answerpapers --- yaksh/models.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 4dd045a..6a7b800 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1186,12 +1186,6 @@ class QuestionPaper(models.Model): ans_paper.questions_order = ",".join(question_ids) ans_paper.save() ans_paper.questions_unanswered.add(*questions) - except AnswerPaper.MultipleObjectsReturned: - 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): -- cgit From 2c53d636aa4a3f36586910e1d3ef5276a7efc337 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 7 Feb 2018 18:49:08 +0530 Subject: Add course as a unique constraint --- yaksh/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 6a7b800..46cf603 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1496,7 +1496,9 @@ class AnswerPaper(models.Model): objects = AnswerPaperManager() class Meta: - unique_together = ('user', 'question_paper', 'attempt_number') + unique_together = ('user', 'question_paper', + 'attempt_number', "course" + ) def get_per_question_score(self, question_id): if question_id not in self.get_questions().values_list('id', flat=True): -- cgit From 440c18f4e0565e0824d432b01bc2be7b8847e122 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 8 Feb 2018 11:43:25 +0530 Subject: Change in forms.py, views.py and models.py - Add new attribute active in lesson and learningmodule model - Change learningmodule get_status method - Add condition in lesson, quiz and module views to check if module is active or not --- yaksh/models.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 1e45851..17ba624 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -155,6 +155,9 @@ class Lesson(models.Model): # Creator of the lesson creator = models.ForeignKey(User) + # Activate/Deactivate Lesson + active = models.BooleanField(default=True) + def __str__(self): return "{0}".format(self.name) @@ -414,6 +417,7 @@ class LearningModule(models.Model): creator = models.ForeignKey(User, related_name="module_creator") check_prerequisite = models.BooleanField(default=True) html_data = models.TextField(null=True, blank=True) + active = models.BooleanField(default=True) is_trial = models.BooleanField(default=False) def get_quiz_units(self): @@ -447,21 +451,22 @@ class LearningModule(models.Model): return ordered_units.get(id=ordered_units_ids[next_index]) def get_status(self, user, course): - """ Get module status if it completed, inprogress or not attempted""" + """ Get module status if completed, inprogress or not attempted""" learning_module = course.learning_module.prefetch_related( "learning_unit").get(id=self.id) ordered_units = learning_module.learning_unit.order_by("order") status_list = [unit.get_completion_status(user, course) - for unit in ordered_units] + for unit in ordered_units + if unit.has_prerequisite()] if not status_list: default_status = "no units" elif all([status == "completed" for status in status_list]): default_status = "completed" - elif "inprogress" in status_list: - default_status = "inprogress" - else: + elif all([status == "not attempted" for status in status_list]): default_status = "not attempted" + else: + default_status = "inprogress" return default_status def is_prerequisite_passed(self, user, course): -- cgit From 617d09ca9b05185d9a2310c106360091ed8a1b1a Mon Sep 17 00:00:00 2001 From: adityacp Date: Fri, 9 Feb 2018 14:56:02 +0530 Subject: Change in models, test_models and views - Change learning module test to remove units from course status after successful test run - Remove unnecessary comments from views - Remove unnecessary condition from module get_status method --- yaksh/models.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 17ba624..fd4ae3f 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -456,8 +456,7 @@ class LearningModule(models.Model): "learning_unit").get(id=self.id) ordered_units = learning_module.learning_unit.order_by("order") status_list = [unit.get_completion_status(user, course) - for unit in ordered_units - if unit.has_prerequisite()] + for unit in ordered_units] if not status_list: default_status = "no units" -- cgit