summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authoradityacp2018-04-04 15:35:22 +0530
committeradityacp2018-04-04 15:35:22 +0530
commit7c04964f7a4cd7d2621e6e4396ffb3bee76d5b0e (patch)
treed44c7d5ea929fae17b3fd1f6f62aaaeddad0964e /yaksh/models.py
parent895102248fedae4dded163bfc8db0bb452f5bb6c (diff)
downloadonline_test-7c04964f7a4cd7d2621e6e4396ffb3bee76d5b0e.tar.gz
online_test-7c04964f7a4cd7d2621e6e4396ffb3bee76d5b0e.tar.bz2
online_test-7c04964f7a4cd7d2621e6e4396ffb3bee76d5b0e.zip
Change views.py, models.py, urls.py, custom_filters.py
- Add new view function to get per student course progress - Change model methods to calculate completion percentage for module and course - Add new url to fetch per student course progress - Remove unnecessary template tag from custom_filter.py
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index d011bb0..4c9ab98 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -551,7 +551,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):
@@ -767,15 +767,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):
@@ -786,6 +785,14 @@ 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():
+ unit = course_status.first().current_unit
+ else:
+ unit = "NA"
+ return unit
+
def days_before_start(self):
""" Get the days remaining for the start of the course """
if timezone.now() < self.start_enroll_time:
@@ -794,6 +801,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
@@ -808,6 +823,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