diff options
author | Prabhu Ramachandran | 2018-06-07 14:24:42 +0530 |
---|---|---|
committer | GitHub | 2018-06-07 14:24:42 +0530 |
commit | 78ce1804d3a82327aa0da1510bb5c03d6bbff3ba (patch) | |
tree | 15aa9ab7a9c5f109d55fe6b5bc37492db58a4237 /yaksh/models.py | |
parent | 94d009bde0bdf3565cf31112a38ff3317fb80f3c (diff) | |
parent | 5da8a3537b1ffb51145cbba0500cedda9f2b48da (diff) | |
download | online_test-78ce1804d3a82327aa0da1510bb5c03d6bbff3ba.tar.gz online_test-78ce1804d3a82327aa0da1510bb5c03d6bbff3ba.tar.bz2 online_test-78ce1804d3a82327aa0da1510bb5c03d6bbff3ba.zip |
Merge pull request #469 from adityacp/enhance_course_status
Enhance course status
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 1ca293b..50a5cc2 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -567,7 +567,7 @@ class LearningModule(models.Model): status_list = [unit.get_completion_status(user, course) for unit in units] count = status_list.count("completed") - percent = round((count / len(units)) * 100) + percent = round((count / units.count()) * 100) return percent def _create_module_copy(self, user, module_name): @@ -783,15 +783,14 @@ class Course(models.Model): next_index = 0 return modules.get(id=module_ids[next_index]) - def percent_completed(self, user): - modules = self.get_learning_modules() + def percent_completed(self, user, modules): if not modules: percent = 0.0 else: status_list = [module.get_module_complete_percent(self, user) for module in modules] count = sum(status_list) - percent = round((count / len(modules))) + percent = round((count / modules.count())) return percent def get_grade(self, user): @@ -802,6 +801,11 @@ class Course(models.Model): grade = "NA" return grade + def get_current_unit(self, user): + course_status = CourseStatus.objects.filter(course=self, user=user) + if course_status.exists(): + return course_status.first().current_unit + def days_before_start(self): """ Get the days remaining for the start of the course """ if timezone.now() < self.start_enroll_time: @@ -810,6 +814,14 @@ class Course(models.Model): remaining_days = 0 return remaining_days + def get_completion_percent(self, user): + course_status = CourseStatus.objects.filter(course=self, user=user) + if course_status.exists(): + percentage = course_status.first().percent_completed + else: + percentage = 0 + return percentage + def __str__(self): return self.name @@ -824,6 +836,7 @@ class CourseStatus(models.Model): user = models.ForeignKey(User) grade = models.CharField(max_length=255, null=True, blank=True) percentage = models.FloatField(default=0.0) + percent_completed = models.IntegerField(default=0) def get_grade(self): return self.grade @@ -862,6 +875,10 @@ class CourseStatus(models.Model): break return complete + def set_current_unit(self, unit): + self.current_unit = unit + self.save() + ############################################################################### class ConcurrentUser(models.Model): |