From f98684da14deb2bbf76088323bc4cf8075026896 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 8 Jan 2018 17:40:40 +0530 Subject: Change in models.py and views.py - Add new model method for course to check last unit and get next module - Change views to allow student to redirect to next module --- yaksh/models.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 1d24bda..208c855 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -668,6 +668,19 @@ class Course(models.Model): module.learning_unit.all().delete() learning_modules.delete() + def is_last_unit(self, module, unit_id): + last_unit = module.get_learning_units().last() + return unit_id == last_unit.id + + def next_module(self, current_module_id): + modules = self.get_learning_modules() + module_ids = list(modules.values_list("id", flat=True)) + current_unit_index = module_ids.index(current_module_id) + next_index = current_unit_index + 1 + if next_index == len(module_ids): + next_index = 0 + return modules.get(id=module_ids[next_index]) + def __str__(self): return self.name -- cgit