From 943d2c1f6d0a1f99ffc6e48bc0c82249e2d4d08c Mon Sep 17 00:00:00 2001 From: adityacp Date: Fri, 12 Jan 2018 17:33:16 +0530 Subject: 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 --- yaksh/models.py | 34 ++++++++++++++++++++++++++++++---- yaksh/urls.py | 2 ++ yaksh/views.py | 17 +++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) (limited to 'yaksh') 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 diff --git a/yaksh/urls.py b/yaksh/urls.py index b4bbb41..d60a5d3 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -166,4 +166,6 @@ urlpatterns = [ views.design_course, name="design_course"), url(r'^manage/courses/designcourse/(?P\d+)/$', views.design_course, name="design_course"), + url(r'^manage/course_status/(?P\d+)/$', + views.course_status, name="course_status"), ] diff --git a/yaksh/views.py b/yaksh/views.py index 49249ca..7049912 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -2666,3 +2666,20 @@ def course_modules(request, course_id, msg=None): context = {"course": course, "learning_modules": learning_modules, "user": user, "msg": msg} return my_render_to_response('yaksh/course_modules.html', context) + + +@login_required +@email_verified +def course_status(request, course_id): + user = request.user + if not is_moderator(user): + raise Http404('You are not allowed to view this page!') + course = get_object_or_404(Course, pk=course_id) + if not course.is_creator(user) and not course.is_teacher(user): + raise Http404('This course does not belong to you') + students = course.get_only_students() + context = { + 'course': course, 'students': students, + 'state': 'course_status', 'modules': course.get_learning_modules() + } + return my_render_to_response('yaksh/course_detail.html', context) -- cgit