diff options
author | adityacp | 2018-01-12 17:33:16 +0530 |
---|---|---|
committer | adityacp | 2018-01-12 17:35:38 +0530 |
commit | 943d2c1f6d0a1f99ffc6e48bc0c82249e2d4d08c (patch) | |
tree | 1dbbb539e525d569bdf5d13bfc0f2fa849eafde8 /yaksh/models.py | |
parent | 3abbc557c57eaf2f3d08222034f9a720a1e7a1ed (diff) | |
download | online_test-943d2c1f6d0a1f99ffc6e48bc0c82249e2d4d08c.tar.gz online_test-943d2c1f6d0a1f99ffc6e48bc0c82249e2d4d08c.tar.bz2 online_test-943d2c1f6d0a1f99ffc6e48bc0c82249e2d4d08c.zip |
Change in models.py, views.py and urls.py
- Add new model methods to calculate percent of module and course completion
- Add new view function for displaying course status
- Add new url to redirect to course status
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index d4a73fa..f37df3b 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -453,12 +453,16 @@ class LearningModule(models.Model): ordered_units = learning_module.learning_unit.order_by("order") status_list = [unit.get_completion_status(user, course) for unit in ordered_units] - if all([status == "completed" for status in status_list]): - return "completed" + + 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: - return "inprogress" + default_status = "inprogress" else: - return "not attempted" + default_status = "not attempted" + return default_status def is_prerequisite_passed(self, user, course): """ Check if prerequisite module is completed """ @@ -481,6 +485,17 @@ class LearningModule(models.Model): def has_prerequisite(self): return self.check_prerequisite + def get_module_complete_percent(self, course, user): + units = self.get_learning_units() + if not units: + percent = 0 + else: + status_list = [unit.get_completion_status(user, course) + for unit in units] + count = status_list.count("completed") + percent = round((count / len(units)) * 100) + return percent + def __str__(self): return self.name @@ -681,6 +696,17 @@ 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() + if not modules: + percent = 0 + else: + status_list = [module.get_module_complete_percent(self, user) + for module in modules] + count = sum(status_list) + percent = round((count / len(modules))) + return percent + def __str__(self): return self.name |