From cc6b19a47146b22ca068c1c156fffcd4b0b5dbc2 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 5 Apr 2021 19:12:36 +0530 Subject: [PATCH 01/21] Optimization of Course Modules page --- yaksh/models.py | 67 ++-- yaksh/templates/yaksh/course_modules.html | 439 ++++++++++++---------- yaksh/templatetags/custom_filters.py | 32 +- yaksh/views.py | 36 +- 4 files changed, 330 insertions(+), 244 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index 8e5562b3d..d60d30390 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -665,17 +665,14 @@ def toggle_check_prerequisite(self): else: self.check_prerequisite = True - def get_completion_status(self, user, course): - course_status = CourseStatus.objects.filter( - user_id=user.id, course_id=course.id - ) + def get_completion_status(self, user, course, course_status): state = "not attempted" - if course_status.exists(): - if course_status.first().completed_units.filter(id=self.id): + if course_status: + if course_status[0].completed_units.filter(id=self.id): state = "completed" elif self.type == "quiz": state = self.quiz.get_answerpaper_status(user, course) - elif course_status.first().current_unit == self: + elif course_status[0].current_unit == self: state = "inprogress" return state @@ -771,23 +768,23 @@ def get_next_unit(self, current_unit_id): next_index = 0 return ordered_units.get(id=ordered_units_ids[next_index]) - def get_status(self, user, course): - """ Get module status if completed, inprogress or not attempted""" - learning_module = course.learning_module.prefetch_related( - "learning_unit").get(id=self.id) - ordered_units = learning_module.learning_unit.order_by("order") - status_list = [unit.get_completion_status(user, course) - for unit in ordered_units] - - if not status_list: - default_status = "no units" - elif all([status == "completed" for status in status_list]): - default_status = "completed" - elif all([status == "not attempted" for status in status_list]): - default_status = "not attempted" - else: - default_status = "inprogress" - return default_status + # def get_status(self, user, course): + # """ Get module status if completed, inprogress or not attempted""" + # learning_module = course.learning_module.prefetch_related( + # "learning_unit").get(id=self.id) + # ordered_units = learning_module.learning_unit.order_by("order") + # status_list = [unit.get_completion_status(user, course) + # for unit in ordered_units] + + # if not status_list: + # default_status = "no units" + # elif all([status == "completed" for status in status_list]): + # default_status = "completed" + # elif all([status == "not attempted" for status in status_list]): + # default_status = "not attempted" + # else: + # default_status = "inprogress" + # return default_status def is_prerequisite_complete(self, user, course): """ Check if prerequisite module is completed """ @@ -1079,7 +1076,11 @@ def get_only_students(self): return students def get_learning_modules(self): - return self.learning_module.filter(is_trial=False).order_by("order") + return self.learning_module.select_related( + None + ).prefetch_related( + 'learning_unit' + ).filter(is_trial=False).order_by("order") def get_learning_module(self, quiz): modules = self.get_learning_modules() @@ -1270,14 +1271,14 @@ def calculate_percentage(self): self.percentage = (sum/total_weightage)*100 self.save() - def is_course_complete(self): - modules = self.course.get_learning_modules() - complete = False - for module in modules: - complete = module.get_status(self.user, self.course) == 'completed' - if not complete: - break - return complete + # def is_course_complete(self): + # modules = self.course.get_learning_modules() + # complete = False + # for module in modules: + # complete = module.get_status(self.user, self.course) == 'completed' + # if not complete: + # break + # return complete def set_current_unit(self, unit): self.current_unit = unit diff --git a/yaksh/templates/yaksh/course_modules.html b/yaksh/templates/yaksh/course_modules.html index 39b9c9763..1059c8f97 100644 --- a/yaksh/templates/yaksh/course_modules.html +++ b/yaksh/templates/yaksh/course_modules.html @@ -1,196 +1,243 @@ -{% extends "user.html" %} -{% load custom_filters %} -{% block title %} Course Modules {% endblock %} - -{% block main %} -
-
-
- {{ course.name }} - Discussion Forum -
-
- {% if course.view_grade %} -
- Grade: {% if grade %} {{ grade }} {% else %} Will be available once the course is complete {% endif %} -
- {% endif %} - {% if msg %} -
- - {{ msg }} -
- {% endif %} - {% if modules %} -
-
-
- Course completed -
-
- - {% if course_percentage %} {{course_percentage}} {% else %} 0 {% endif %}% - -
-
-
- {% if course_percentage %} - {% if course_percentage <= 50 %} -
-
- {% elif course_percentage <= 75 %} -
-
- {% else %} -
-
- {% endif %} - {% endif %} -
-
- {% else %} -
- No lectures found -
- {% endif %} -
-
-
- {% for module, percent in modules %} -
-
-
-
-
- {{ module.name|title }} -
- - -
-
-
-
- Module completed -
-
- - {% if percent %} {{percent}} {% else %} 0 {% endif %}% - -
-
-
- {% if percent %} - {% get_module_status user module course as module_status %} - {% if module_status == "completed" %} -
- {% elif module_status == "inprogress" %} -
- {% endif %} - {% endif %} -
-
-
-
-
-
-
- - {% for unit in module.get_learning_units %} - - - - - - - - {% endfor %} -
- {% if unit.type == "quiz" %} - {% if unit.quiz.is_exercise %} - - {% else %} - - {% endif %} - {% else %} - - {% endif %} - - {% if unit.type == "quiz" %} - {{unit.quiz.description}} - {% else %} - {{unit.lesson.name}} - {% endif %} - - {% if unit.type == "lesson" %} - - View - - {% else %} - {% if unit.quiz.questionpaper_set.get %} - - View - - {% endif %} - {% endif %} - - {% get_unit_status course module unit user as status %} - {% if status == "completed" %} - {{status|title}} - - {% elif status == "inprogress" %} - {{status|title}} - - {% else %} - {{status|title}} - - {% endif %} - - {% if unit.type == "quiz" %} - {% if unit.quiz.view_answerpaper %} - -  Answer paper - {% else %} - - Answer paper - {% endif %} - {% else %} - ------ - {% endif %} -
-
-
-
-
-
- {% endfor %} -
-{% endblock %} +{% extends 'user.html' %} +{% load custom_filters %} + +{% block title %} + Course Modules +{% endblock title %} + + +{% block main %} +
+
+
+ {{course.name}} + Discussion Forum +
+
+ + {% if course.view_grade %} +
+ Grade: {% if grade %} {{ grade }} {% else %} Will be available once the course is complete {% endif %} +
+ {% endif %} + + {% if msg %} +
+ + {{ msg }} +
+ {% endif %} + + + {% if modules %} +
+
+
+ Course completed +
+
+ + + {% if course_percentage %} + {{course_percentage}} + {% else %} + 0 + {% endif %} + + +
+
+
+ + {% if course_percentage %} + {% if course_percentage <= 50 %} +
+
+ {% elif course_percentage <= 75 %} +
+
+ {% else %} +
+
+ {% endif %} + {% endif %} + +
+
+ {% else %} +
+ No lectures found +
+ {% endif %} + +
+
+
+ + {% for module, units in modules.items %} +
+
+
+
+
+ {{module.name|title}} +
+ + +
+
+
+
+ Module completed +
+
+ + + {% module_completion_percent units status.1 as percent %} + {{percent}}% + +
+
+
+ + {% if status.0 == 'completed' %} +
+
+ {% elif status.0 == 'inprogress' %} +
+
+ {% endif %} +
+
+
+
+
+
+
+ + {% for unit in units %} + + + + + + + + {% endfor %} +
+ {% if unit.type == "quiz" %} + {% if unit.quiz.is_exercise %} + + {% else %} + + {% endif %} + {% else %} + + {% endif %} + + {% if unit.type == "quiz" %} + {{unit.quiz.description}} + {% else %} + {{unit.lesson.name}} + {% endif %} + + {% if unit.type == "lesson" %} + + View + + {% else %} + {% if unit.quiz.questionpaper_set.get %} + + View + + {% endif %} + {% endif %} + + {% for cur_unit, st in status.1.items %} + {% if unit == cur_unit %} + {% if st == "completed" %} + {{st|title}} + + {% elif st == "inprogress" %} + {{st|title}} + + {% else %} + {{st|title}} + + {% endif %} + {% endif %} + {% endfor %} + + {% if unit.type == 'quiz' %} + {% if unit.quiz.view_answerpaper %} + +  Answer paper + {% else %} + + Answer paper + + {% endif %} + {% else %} + ------ + {% endif %} +
+
+
+
+
+ {% endfor %} +
+{% endblock main %} \ No newline at end of file diff --git a/yaksh/templatetags/custom_filters.py b/yaksh/templatetags/custom_filters.py index bd97d2e11..d3275bd81 100644 --- a/yaksh/templatetags/custom_filters.py +++ b/yaksh/templatetags/custom_filters.py @@ -54,13 +54,28 @@ def file_title(name): @register.simple_tag -def get_unit_status(course, module, unit, user): - return course.get_unit_completion_status(module, user, unit) +def get_unit_status(user, course, course_status, unit): + return unit.get_completion_status(user, course, course_status) @register.simple_tag -def get_module_status(user, module, course): - return module.get_status(user, course) +def get_module_status(user, module, units, course, course_status): + + status = {} + for unit in units: + status[unit] = unit.get_completion_status(user, course, course_status) + + if not status: + default_status = "no units" + elif all([status == "completed" for unit, status in status.items()]): + default_status = "completed" + elif all([status == "not attempted" for unit, status in status.items()]): + default_status = "not attempted" + else: + default_status = "inprogress" + + return (default_status, status) + @register.simple_tag @@ -69,9 +84,14 @@ def get_course_details(course): @register.simple_tag -def module_completion_percent(course, module, user): - return module.get_module_complete_percent(course, user) +def module_completion_percent(units, status_list): + if not units: + percent = 0.0 + else: + count = sum(map(('completed').__eq__, status_list.values())) + percent = round((count / units.count()) * 100) + return percent @register.simple_tag def get_ordered_testcases(question, answerpaper): diff --git a/yaksh/views.py b/yaksh/views.py index 37275149a..17a4031e2 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3204,16 +3204,34 @@ def course_modules(request, course_id, msg=None): return quizlist_user(request, msg=msg) learning_modules = course.get_learning_modules() context = {"course": course, "user": user, "msg": msg} - course_status = CourseStatus.objects.filter(course=course, user=user) - context['course_percentage'] = course.get_completion_percent(user) - context['modules'] = [ - (module, module.get_module_complete_percent(course, user)) - for module in learning_modules - ] - if course_status.exists(): - course_status = course_status.first() + course_status = list(CourseStatus.objects.select_related( + 'current_unit' + ).prefetch_related( + 'completed_units' + ).filter( + course=course, user=user + )) + context['course_status'] = course_status + context['course_percentage'] = course_status[0].percent_completed + + # context['modules'] = [ + # (module, module.get_module_complete_percent(course, user)) + # for module in learning_modules + # ] + + module_learning_units = {} + for module in learning_modules: + module_learning_units[module] = module.learning_unit.select_related( + 'lesson', 'quiz' + ).prefetch_related('quiz__questionpaper_set').order_by("order") + + context['modules'] = module_learning_units + + if course_status: + course_status = course_status[0] if not course_status.grade: - course_status.set_grade() + pass + # course_status.set_grade() context['grade'] = course_status.get_grade() return my_render_to_response(request, 'yaksh/course_modules.html', context) From e7c65b683007d29c202479852178b79cb23fb013 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Wed, 7 Apr 2021 15:17:39 +0530 Subject: [PATCH 02/21] Student dashboard optimization --- yaksh/templates/yaksh/all_courses.html | 114 ++++++++++++ yaksh/templates/yaksh/quizzes_user.html | 225 ++++++------------------ yaksh/templatetags/custom_filters.py | 16 +- yaksh/views.py | 42 +++-- 4 files changed, 203 insertions(+), 194 deletions(-) create mode 100644 yaksh/templates/yaksh/all_courses.html diff --git a/yaksh/templates/yaksh/all_courses.html b/yaksh/templates/yaksh/all_courses.html new file mode 100644 index 000000000..9db6a2216 --- /dev/null +++ b/yaksh/templates/yaksh/all_courses.html @@ -0,0 +1,114 @@ +{% load custom_filters %} +
+
+
+
+ {{course.name}} +
+ +
+ {% if user in course.requests.all %} + + Request Pending + + {% elif user in course.rejected.all %} + + Request Rejected + + {% elif user in course.students.all %} + {% if course.completion_percentage > 0 %} + + Continue + + {% else %} + + Start + + {% endif %} + {% else %} + {% if course.active %} + {% if course.is_active_enrollment %} + {% if course.is_self_enroll %} + Enroll + {% else %} + Enroll + {% endif %} + {% else %} + + No Enrollments allowed + + {% endif %} + {% else %} + + Inactive Course + + {% endif %} + {% endif %} +
+
+ {% show_special_attempt user course %} +
+
+
+
+
+

Instructor: {{course.creator.get_full_name|title}}

+ {% with course.learning_module.all as modules %} + {% if modules %} +

Course Content +

    + {% for module in modules %} +
  • {{module.name|title}}
  • + {% endfor %} +
+

+ {% endif %} + {% endwith %} + {% if course.instructions %} +

Instructions
+ {{ course.instructions|safe }} +

+ {% endif %} +
+
+

Starts On: {{course.start_enroll_time}}

+

Ends On: {{course.end_enroll_time}}

+ {% get_course_completion_percent course.coursestatus_set.all user as percent %} +
+
+
+ Course completed +
+
+ + {% if percent %} {{percent}}% {% endif %} + +
+
+
+ {% if percent %} + {% if percent <= 50 %} +
+
+ {% elif percent <= 75 %} +
+
+ {% else %} +
+
+ {% endif %} + {% endif %} +
+
+
+
+
+
+
\ No newline at end of file diff --git a/yaksh/templates/yaksh/quizzes_user.html b/yaksh/templates/yaksh/quizzes_user.html index 3dfcbac2e..1f14bd284 100644 --- a/yaksh/templates/yaksh/quizzes_user.html +++ b/yaksh/templates/yaksh/quizzes_user.html @@ -1,181 +1,68 @@ {% extends "user.html" %} -{% load custom_filters %} {% block title %} Student Dashboard {% endblock %} -{% block script %} - -{% endblock %} - {% block main %} -
-
-

{{title}}

-
-
-
-
-
- {% csrf_token %} -
-
- - - - +
+
+

{{title}}

+
+
+
+
+ + {% csrf_token %} +
+
+ + + + +
+ +
+ {% if "Search" in title %} + - -
- {% if "Search" in title %} - - {% endif %} -
-
- {% if messages %} - {% for message in messages %} -
- - {{ message }} + {% endif %}

- {% endfor %} - {% endif %} - - {% if not courses %} -
- {% endif %} -
-
-
- {% for course in courses %} -
-
-
-
{{course.data.name}}
- -
- {% if user in course.data.requests.all %} - - Request Pending - - {% elif user in course.data.rejected.all %} - - Request Rejected - - {% elif user in course.data.students.all %} - {% if course.completion_percentage > 0 %} - - Continue - - {% else %} - - Start - - {% endif %} - {% else %} - {% if course.data.active %} - {% if course.data.is_active_enrollment %} - {% if course.data.is_self_enroll %} - Enroll - {% else %} - Enroll - {% endif %} - {% else %} - - No Enrollments allowed - - {% endif %} - {% else %} - - Inactive Course - - {% endif %} - {% endif %} -
-
- {% show_special_attempt user.id course.data.id %} -
-
-
-
-
-

Instructor: {{course.data.creator.get_full_name|title}}

- {% with course.data.get_learning_modules as modules %} - {% if modules %} -

- Course Content -

    - {% for module in modules %} -
  • {{module.name|title}}
  • - {% endfor %} -
-

- {% endif %} - {% endwith %} - {% if course.data.instructions %} -

- Instructions
- {{ course.data.instructions|safe }} -

- {% endif %} -
-
-

Starts On: {{course.data.start_enroll_time}}

-

Ends On: {{course.data.end_enroll_time}}

- {% with course.completion_percentage as percent %} -
-
-
- Course completed -
-
- - {% if percent %} {{percent}} {% else %} 0 {% endif %}% - -
-
-
- {% if percent %} - {% if percent <= 50 %} -
-
- {% elif percent <= 75 %} -
-
- {% else %} -
-
- {% endif %} - {% endif %} -
-
- {% endwith %} -
-
-
-
-
-
+ {% if messages %} + {% for message in messages %} +
+ + {{ message }} +
+
{% endfor %} + {% endif %} + {% if not enrolled_courses or not remaining_courses %} +
+ +
+ {% endif %} +
+
+
+ +

Enrolled Courses

+ {% for course in enrolled_courses %} + {% include 'yaksh/all_courses.html' %} + {% endfor %} + +

Other Courses

+ {% for course in remaining_courses %} + {% include 'yaksh/all_courses.html' %} + {% endfor %} +
-
- -{% endblock %} - +{% endblock %} \ No newline at end of file diff --git a/yaksh/templatetags/custom_filters.py b/yaksh/templatetags/custom_filters.py index d3275bd81..a43b7b942 100644 --- a/yaksh/templatetags/custom_filters.py +++ b/yaksh/templatetags/custom_filters.py @@ -83,6 +83,17 @@ def get_course_details(course): return course.get_quiz_details() +@register.simple_tag +def get_course_completion_percent(courses_status, user): + course_status = courses_status.filter( + user=user + ).values('percent_completed') + if course_status: + return course_status.first()['percent_completed'] + else: + return 0 + + @register.simple_tag def module_completion_percent(units, status_list): if not units: @@ -190,9 +201,8 @@ def to_str(text): @register.inclusion_tag('yaksh/micromanaged.html') -def show_special_attempt(user_id, course_id): - user = User.objects.get(pk=user_id) - micromanagers = user.micromanaged.filter(course_id=course_id) +def show_special_attempt(user, course): + micromanagers = user.micromanaged.filter(course_id=course.id) context = {'micromanagers': micromanagers} return context diff --git a/yaksh/views.py b/yaksh/views.py index 17a4031e2..c1419924c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -181,7 +181,8 @@ def user_logout(request): def quizlist_user(request, enrolled=None, msg=None): """Show All Quizzes that is available to logged-in user.""" user = request.user - courses_data = [] + context = {} + courses_data = {} if request.method == "POST": course_code = request.POST.get('course_code') @@ -189,33 +190,30 @@ def quizlist_user(request, enrolled=None, msg=None): courses = hidden_courses title = 'Search Results' else: - enrolled_courses = user.students.filter(is_trial=False).order_by('-id') - remaining_courses = list(Course.objects.filter( + enrolled_courses = user.students.select_related('creator').prefetch_related( + 'students', + 'requests', + 'rejected', + 'learning_module', + ).filter( + is_trial=False + ).order_by("-id") + remaining_courses = Course.objects.filter( active=True, is_trial=False, hidden=False ).exclude( id__in=enrolled_courses.values_list("id", flat=True) - ).order_by('-id')) - courses = list(enrolled_courses) - courses.extend(remaining_courses) - title = 'All Courses' + ).order_by("-id") - for course in courses: - if course.students.filter(id=user.id).exists(): - _percent = course.get_completion_percent(user) - else: - _percent = None - courses_data.append( - { - 'data': course, - 'completion_percentage': _percent, - } - ) + + context['enrolled_courses'] = enrolled_courses + context['remaining_courses'] = remaining_courses + + title = 'All Courses' messages.info(request, msg) - context = { - 'user': user, 'courses': courses_data, - 'title': title - } + + context['user'] = user + context['title'] = title return my_render_to_response(request, "yaksh/quizzes_user.html", context) From 704b67745774da92226960b2a727b4305a40a88e Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Thu, 22 Apr 2021 18:52:22 +0530 Subject: [PATCH 03/21] View Module page optimization --- yaksh/models.py | 74 ++-- yaksh/templates/yaksh/all_courses.html | 2 +- yaksh/templates/yaksh/show_video.html | 501 ++++++++++++------------- yaksh/templatetags/custom_filters.py | 6 +- yaksh/views.py | 53 ++- 5 files changed, 322 insertions(+), 314 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index d60d30390..26a415719 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -667,12 +667,12 @@ def toggle_check_prerequisite(self): def get_completion_status(self, user, course, course_status): state = "not attempted" - if course_status: - if course_status[0].completed_units.filter(id=self.id): + if course_status.exists(): + if course_status.first().completed_units.filter(id=self.id): state = "completed" elif self.type == "quiz": state = self.quiz.get_answerpaper_status(user, course) - elif course_status[0].current_unit == self: + elif course_status.first().current_unit == self: state = "inprogress" return state @@ -768,23 +768,23 @@ def get_next_unit(self, current_unit_id): next_index = 0 return ordered_units.get(id=ordered_units_ids[next_index]) - # def get_status(self, user, course): - # """ Get module status if completed, inprogress or not attempted""" - # learning_module = course.learning_module.prefetch_related( - # "learning_unit").get(id=self.id) - # ordered_units = learning_module.learning_unit.order_by("order") - # status_list = [unit.get_completion_status(user, course) - # for unit in ordered_units] - - # if not status_list: - # default_status = "no units" - # elif all([status == "completed" for status in status_list]): - # default_status = "completed" - # elif all([status == "not attempted" for status in status_list]): - # default_status = "not attempted" - # else: - # default_status = "inprogress" - # return default_status + def get_status(self, user, course, course_status): + """ Get module status if completed, inprogress or not attempted""" + learning_module = course.learning_module.prefetch_related( + "learning_unit").get(id=self.id) + ordered_units = learning_module.learning_unit.order_by("order") + status_list = [unit.get_completion_status(user, course, course_status) + for unit in ordered_units] + + if not status_list: + default_status = "no units" + elif all([status == "completed" for status in status_list]): + default_status = "completed" + elif all([status == "not attempted" for status in status_list]): + default_status = "not attempted" + else: + default_status = "inprogress" + return default_status def is_prerequisite_complete(self, user, course): """ Check if prerequisite module is completed """ @@ -842,12 +842,12 @@ def is_prerequisite_passed(self, user, course): def has_prerequisite(self): return self.check_prerequisite - def get_module_complete_percent(self, course, user): + def get_module_complete_percent(self, course, user, course_status): units = self.get_learning_units() if not units: percent = 0.0 else: - status_list = [unit.get_completion_status(user, course) + status_list = [unit.get_completion_status(user, course, course_status) for unit in units] count = status_list.count("completed") percent = round((count / units.count()) * 100) @@ -1090,10 +1090,8 @@ def get_learning_module(self, quiz): break return module - def get_unit_completion_status(self, module, user, unit): - course_module = self.learning_module.get(id=module.id) - learning_unit = course_module.learning_unit.get(id=unit.id) - return learning_unit.get_completion_status(user, self) + def get_unit_completion_status(self, unit, user, course_status): + return unit.get_completion_status(user, self, course_status) def get_quizzes(self): learning_modules = self.learning_module.all() @@ -1154,10 +1152,12 @@ def next_module(self, current_module_id): return modules.get(id=module_ids[next_index]) def percent_completed(self, user, modules): + course_status = CourseStatus.objects.filter( + course_id=self.id, user_id=user.id) if not modules: percent = 0.0 else: - status_list = [module.get_module_complete_percent(self, user) + status_list = [module.get_module_complete_percent(self, user, course_status) for module in modules] count = sum(status_list) percent = round((count / modules.count())) @@ -1244,8 +1244,8 @@ class CourseStatus(models.Model): def get_grade(self): return self.grade - def set_grade(self): - if self.is_course_complete(): + def set_grade(self, course_status, module_learning_units): + if self.is_course_complete(course_status, module_learning_units): self.calculate_percentage() if self.course.grading_system is None: grading_system = GradingSystem.objects.get( @@ -1271,14 +1271,14 @@ def calculate_percentage(self): self.percentage = (sum/total_weightage)*100 self.save() - # def is_course_complete(self): - # modules = self.course.get_learning_modules() - # complete = False - # for module in modules: - # complete = module.get_status(self.user, self.course) == 'completed' - # if not complete: - # break - # return complete + def is_course_complete(self, course_status, module_learning_units): + modules = module_learning_units.keys() + complete = False + for module in modules: + complete = module.get_status(self.user, self.course, course_status) == 'completed' + if not complete: + break + return complete def set_current_unit(self, unit): self.current_unit = unit diff --git a/yaksh/templates/yaksh/all_courses.html b/yaksh/templates/yaksh/all_courses.html index 9db6a2216..a5087f247 100644 --- a/yaksh/templates/yaksh/all_courses.html +++ b/yaksh/templates/yaksh/all_courses.html @@ -88,7 +88,7 @@
- {% if percent %} {{percent}}% {% endif %} + {% if percent > 0 %} {{percent}}% {%else%} {{percent}}% {% endif %}
diff --git a/yaksh/templates/yaksh/show_video.html b/yaksh/templates/yaksh/show_video.html index faa773511..136911a34 100644 --- a/yaksh/templates/yaksh/show_video.html +++ b/yaksh/templates/yaksh/show_video.html @@ -3,288 +3,281 @@ {% load custom_filters %} {% block title %} {{ learning_module.name }} {% endblock %} + {% block script %} - + {% endblock %} + {% block main %} -
- +
- - +
- -

- + +

+ +
+ {% if msg %} +
+
+ + {{ msg }} +
+
+ {% endif %} + {% if state == "module" %} + {% if learning_module.html_data %} + {{learning_module.html_data|safe}} + {% else %} + No Module information + {% endif %}
- {% if msg %} -
-
- - {{ msg }} -
-
+ {% if first_unit %} + Start + + + + {% else %} + Next + + + {% endif %} - - - {% if state == "module" %} - {% if learning_module.html_data %} - {{learning_module.html_data|safe}} - {% else %} - No Module information - {% endif %} -
- {% if first_unit %} - Start - - - - {% else %} - Next - - - - {% endif %} - {% else %} - -
- {% if lesson.video_path %} -
-
- {% with lesson.video_path|video_name as video %} - {% if video.1 == "others" %} - - {% else %} -
- {% endif %} - {% endwith %} -
+ {% else %} + +
+ {% if lesson.video_path %} +
+
+ {% with lesson.video_path|video_name as video %} + {% if video.1 == "others" %} + + {% else %} +
+ {% endif %} + {% endwith %} +
+
+ {% if toc %} +
+
+ +
+
+ + {% for content in toc %} + {% with content.get_toc_text as toc_name %} + + + + + + + + {% endwith %} + {% empty %} +
+ No Table of contents added +
+ {% endfor %} +
+ + {{ toc_name }} + + + {{content.get_content_display}} + + {{content.time}} +
- {% if toc %} -
-
- -
-
- - {% for content in toc %} - {% with content.get_toc_text as toc_name %} - - - - - - - - {% endwith %} - {% empty %} -
- No Table of contents added -
- {% endfor %} -
- - {{ toc_name }} - - - {{content.get_content_display}} - - {{content.time}} -
-
-
+
+
+
+ {% endif %} + {% endif %} +
+
+ {% csrf_token %} + + +
+
+

Lesson Description

+
+
+ {{lesson.html_data|safe}} +
+
+
+ {% with lesson.get_files as lesson_files %} + {% if lesson_files %} +
+
+ Files for this lesson
-
- {% endif %} - {% endif %} -
-
- {% csrf_token %} - - -
-
-

Lesson Description

-
- {{lesson.html_data|safe}} -
-
-
- {% with lesson.get_files as lesson_files %} - {% if lesson_files %} -
-
- Files for this lesson -
-
- {% for f in lesson_files %} - - {{forloop.counter}}.{{ f.file.name|file_title }} - - {% endfor %} -
-
- {% endif %} - {% endwith %} -
+ {% for f in lesson_files %} + + {{forloop.counter}}.{{ f.file.name|file_title }} + + {% endfor %}
-
+
+ {% endif %} + {% endwith %} +
+
-
- - Next  - - {% endif %} +
+
+ + Next  + + {% endif %} {% if state == 'lesson' %} -
-
- Comments: -
-
- {% csrf_token %} - {{form.as_p}} -
- -
-
+
+
+ Comments: +
+
+ {% csrf_token %} + {{form.as_p}} +
+ +
+
{% endif %}
{% if comments %} - {% for comment in comments %} -
-
-
-
- - {% if comment.anonymous %} - Anonymous - {% else %} - {{comment.creator.username}} - {% endif %} - -
-
- {{comment.created_at}} {% if user.profile.is_moderator %} {% endif %} -
-
-

{{comment.description|safe}}

-
- {% if comment.image %} - -
-
- {% endif %} -
-
+ {% for comment in comments %} +
+
+
+
+ + {% if comment.anonymous %} + Anonymous + {% else %} + {{comment.creator.username}} + {% endif %} + +
+
+ {{comment.created_at}} {% if user.profile.is_moderator %} {% endif %} +
+
+

{{comment.description|safe}}

+
+ {% if comment.image %} + +
+
+ {% endif %}
- {% endfor %} +
+
+ {% endfor %} {% endif %}
-
- +
\ No newline at end of file diff --git a/yaksh/views.py b/yaksh/views.py index 4c9103475..ecdf6f009 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3107,18 +3107,25 @@ def design_course(request, course_id): user = request.user if not is_moderator(user): raise Http404('You are not allowed to view this page!') - course = Course.objects.get(id=course_id) + course = Course.objects.prefetch_related( + Prefetch( + 'learning_module', + queryset=LearningModule.objects.filter( + is_trial=False + ).order_by("order") + ) + ).get(id=course_id) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') context = {} + course_modules = course.learning_module.prefetch_related('learning_unit') if request.method == "POST": if "Add" in request.POST: add_values = request.POST.getlist("module_list") to_add_list = [] if add_values: - ordered_modules = course.get_learning_modules() - if ordered_modules.exists(): - start_val = ordered_modules.last().order + 1 + if course_modules.exists(): + start_val = course_modules.last().order + 1 else: start_val = 1 for order, value in enumerate(add_values, start_val): @@ -3182,13 +3189,20 @@ def design_course(request, course_id): else: messages.warning(request, "Please select atleast one module") - added_learning_modules = course.get_learning_modules() - all_learning_modules = LearningModule.objects.filter( - creator=user, is_trial=False) + learning_modules = LearningModule.objects.filter( + creator=user, is_trial=False + ).prefetch_related( + 'learning_unit' + ).exclude(id__in=course_modules.values_list('id', flat=True)) + + module_units = {} + for module in learning_modules: + module_units[module] = module.learning_unit.select_related( + 'lesson', 'quiz' + ) - learning_modules = set(all_learning_modules) - set(added_learning_modules) - context['added_learning_modules'] = added_learning_modules - context['learning_modules'] = learning_modules + context['added_module_units'] = course_modules + context['module_units'] = module_units context['course'] = course context['is_design_course'] = True return my_render_to_response( From 079f3d63111fad3e4f52788601429be35da141dc Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Thu, 10 Jun 2021 21:44:09 +0530 Subject: [PATCH 16/21] Optimize 'Course Progress' tab in Manage Course --- yaksh/models.py | 21 ++-- yaksh/templates/yaksh/course_progress.html | 135 +++++++++++---------- yaksh/views.py | 38 ++++-- 3 files changed, 104 insertions(+), 90 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index a8ac39bb5..758382f43 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1146,18 +1146,16 @@ def percent_completed(self, user, modules): percent = round((count / modules.count())) return percent - def get_grade(self, user): - course_status = CourseStatus.objects.filter(course=self, user=user) - if course_status.exists(): - grade = course_status.first().get_grade() + def get_grade(self, user, course_status): + if course_status: + grade = course_status.get_grade() else: grade = "NA" return grade - def get_current_unit(self, user): - course_status = CourseStatus.objects.filter(course=self, user_id=user) - if course_status.exists(): - return course_status.first().current_unit + def get_current_unit(self, user, course_status): + if course_status: + return course_status.current_unit def days_before_start(self): """ Get the days remaining for the start of the course """ @@ -1167,10 +1165,9 @@ def days_before_start(self): 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 + def get_completion_percent(self, user, course_status): + if course_status: + percentage = course_status.percent_completed else: percentage = 0 return percentage diff --git a/yaksh/templates/yaksh/course_progress.html b/yaksh/templates/yaksh/course_progress.html index 2d3dbf7e9..7420cabb8 100644 --- a/yaksh/templates/yaksh/course_progress.html +++ b/yaksh/templates/yaksh/course_progress.html @@ -1,87 +1,88 @@ {% if is_progress %} -
- {% if student_details %} -
-

Course Progress

-
-
-
- Number Of Students: {{ students_no }} -
- -
-
+
+ {% if stud_details %} +
+

+ Course Progress +


- {% include "yaksh/paginator.html" %} -
- {% if student_details|length > 10 %} -
- {% else %} -
- {% endif %} - - - - - - - - - - - - - {% for student, grade, percent, unit in student_details %} +
+
+ Number of Students: {% if total_students %} {{total_students}} {% else %} 0 {% endif %} +
+ +
+ +
+ {% include "yaksh/paginator.html" %} +
+
10 %}style="height: 700px"{% endif %}> +
Sr. NoRoll No.NameCurrent UnitCompletion PercentageGrade
+ + + + + + + + + + + {% for student, grade, percent, unit in stud_details %} + - - {% endfor %} - -
Sr. NoRoll No.NameCurrent UnitCompletion PercentageGrade
{{forloop.counter}} - {{ student.profile.roll_number}} + {{student.profile.roll_number}} - - - {{ student.get_full_name|title}} - - - + + + {{ student.get_full_name|title}} + + + - {% if unit %} - {% if unit.type == 'quiz' %} - {{unit.quiz.description}} - {% else %} - {{unit.lesson.name}} - {% endif %} + {% if unit %} + {% if unit.type == 'quiz' %} + {{unit.quiz.description}} {% else %} - NA - {% endif%} + {{unit.lesson.name}} + {% endif %} + {% else %} + NA + {% endif %} - {{ percent }} % + {{percent}} - {{ grade }} + {{grade}}
-
+ + {% endfor %} + +
- {% include "yaksh/paginator.html" %} +
+ {% include "yaksh/paginator.html" %} {% else %} -
- - No course data found - -
+
+ + No course data found + +
{% endif %} -
- +
{% endif %} \ No newline at end of file diff --git a/yaksh/views.py b/yaksh/views.py index ecdf6f009..92b8aab8b 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3318,26 +3318,42 @@ def course_modules(request, course_id, msg=None): @login_required @email_verified def course_status(request, course_id): + context = {} 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) + course = Course.objects.prefetch_related( + 'students', 'coursestatus_set' + ).get(id=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.students.order_by("-id") - students_no = students.count() + students = course.students.select_related('profile').order_by("-id") + total_students = students.count() paginator = Paginator(students, 100) page = request.GET.get('page') students = paginator.get_page(page) - stud_details = [(student, course.get_grade(student), - course.get_completion_percent(student), - course.get_current_unit(student.id)) - for student in students.object_list] - context = { - 'course': course, 'objects': students, 'is_progress': True, - 'student_details': stud_details, 'students_no': students_no - } + course_statuses = course.coursestatus_set.select_related( + 'current_unit', 'current_unit__lesson', 'current_unit__quiz' + ) + user_course_status = {} + for status in course_statuses: + user_course_status[status.user.id] = status + + stud_details = [] + for student in students: + course_status = user_course_status.get(student.id) + grade = course.get_grade(student, course_status) + percent = course.get_completion_percent(student, course_status) + unit = course.get_current_unit(student, course_status) + stud_details.append((student, grade, percent, unit)) + + context['objects'] = students + context['total_students'] = total_students + context['stud_details'] = stud_details + context['is_progress'] = True + context['course'] = course + return my_render_to_response(request, 'yaksh/course_detail.html', context) From 8a6e0eee7a73b3f7b66d2c99c542f85e708c303d Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 14 Jun 2021 16:56:38 +0530 Subject: [PATCH 17/21] Optimize 'Enrollments' in Manage Course --- yaksh/models.py | 6 +++--- yaksh/views.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index 758382f43..b0680989b 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -953,7 +953,7 @@ def request(self, *users): self.requests.add(*users) def get_requests(self): - return self.requests.all() + return self.requests.select_related('profile') def is_active_enrollment(self): return self.start_enroll_time <= timezone.now() < self.end_enroll_time @@ -966,7 +966,7 @@ def enroll(self, was_rejected, *users): self.rejected.remove(*users) def get_enrolled(self): - return self.students.all() + return self.students.select_related('profile') def reject(self, was_enrolled, *users): self.rejected.add(*users) @@ -976,7 +976,7 @@ def reject(self, was_enrolled, *users): self.students.remove(*users) def get_rejected(self): - return self.rejected.all() + return self.rejected.select_related('profile') def is_enrolled(self, user): return self.students.filter(id=user.id).exists() diff --git a/yaksh/views.py b/yaksh/views.py index 92b8aab8b..5f926bd7c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3481,7 +3481,10 @@ def course_teachers(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) + + course = Course.objects.prefetch_related( + 'students', 'requests', 'rejected' + ).get(id=course_id) if not course.is_creator(user) and not course.is_teacher(user): raise Http404("You are not allowed to view {0}".format( course.name)) From 6e7b98f9166f11f3807964f96eeefce1cfc1a922 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Tue, 15 Jun 2021 17:58:04 +0530 Subject: [PATCH 18/21] Minor changes in Monitor --- yaksh/models.py | 18 +++++++++++++----- yaksh/views.py | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index b0680989b..b49278f17 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -2118,12 +2118,20 @@ def get_user_all_attempts(self, questionpaper, user, course_id): def get_user_data(self, user, questionpaper_id, course_id, attempt_number=None): if attempt_number is not None: - papers = self.filter(user_id=user.id, - question_paper_id__in=questionpaper_id, - course_id=course_id, - attempt_number=attempt_number) + papers = self.select_related( + 'course', 'question_paper__quiz' + ).prefetch_related( + 'answers', 'questions' + ).filter(user_id=user.id, + question_paper_id__in=questionpaper_id, + course_id=course_id, + attempt_number=attempt_number) else: - papers = self.filter( + papers = self.select_related( + 'course', 'question_paper__quiz' + ).prefetch_related( + 'answers', 'questions' + ).filter( user=user, question_paper_id=questionpaper_id, course_id=course_id ).order_by("-attempt_number") diff --git a/yaksh/views.py b/yaksh/views.py index 5f926bd7c..47a40f1ee 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1981,7 +1981,7 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None, answer_paper__question_paper_id__in=questionpaper_id, answer_paper__user_id=user_id ).exists() - user = User.objects.get(id=user_id) + user = User.objects.select_related('profile').get(id=user_id) data = AnswerPaper.objects.get_user_data( user, questionpaper_id, course_id, attempt_number ) From b830215eb05b30774937b40e14a8a87d15fbbebb Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Wed, 16 Jun 2021 17:29:12 +0530 Subject: [PATCH 19/21] Monitor optimization --- yaksh/templates/yaksh/monitor.html | 4 ++-- yaksh/templatetags/custom_filters.py | 5 ++--- yaksh/views.py | 4 +++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/yaksh/templates/yaksh/monitor.html b/yaksh/templates/yaksh/monitor.html index 6fd3cb1cb..970dd0386 100644 --- a/yaksh/templates/yaksh/monitor.html +++ b/yaksh/templates/yaksh/monitor.html @@ -4,7 +4,7 @@ {% block title %} Monitor {% endblock %} {% block pagetitle %} Monitor {% endblock pagetitle %} -{% block meta %} {% endblock meta %} +{# {% block meta %} {% endblock meta %} #} {% block script %} {% if papers %} @@ -206,7 +206,7 @@
- {% specail_attempt_monitor paper.user.id course.id quiz.id %} + {% special_attempt_monitor paper.user course.id quiz.id %} {% endfor %} diff --git a/yaksh/templatetags/custom_filters.py b/yaksh/templatetags/custom_filters.py index 13aca1fe4..8d7476409 100644 --- a/yaksh/templatetags/custom_filters.py +++ b/yaksh/templatetags/custom_filters.py @@ -208,11 +208,10 @@ def show_special_attempt(user, course): @register.inclusion_tag('yaksh/micromonitor.html') -def specail_attempt_monitor(user_id, course_id, quiz_id): - user = User.objects.get(pk=user_id) +def special_attempt_monitor(user, course_id, quiz_id): micromanagers = user.micromanaged.filter(course_id=course_id, quiz_id=quiz_id) - context = {'user_id': user_id, 'course_id': course_id, 'quiz_id': quiz_id} + context = {'user_id': user.id, 'course_id': course_id, 'quiz_id': quiz_id} if micromanagers.exists(): context['micromanager'] = micromanagers.first() return context diff --git a/yaksh/views.py b/yaksh/views.py index 47a40f1ee..272184d0c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1431,7 +1431,9 @@ def monitor(request, quiz_id=None, course_id=None, attempt_number=1): questions_attempted = {} completed_papers = 0 inprogress_papers = 0 - papers = AnswerPaper.objects.filter( + papers = AnswerPaper.objects.select_related( + 'user', 'user__profile', 'question_paper__quiz' + ).filter( question_paper_id=q_paper.id, attempt_number=attempt_number, course_id=course_id ).order_by('user__first_name') From 7fb5f3c8ec291bcd4aeae0614df77715dd632ea0 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Wed, 23 Jun 2021 17:04:02 +0530 Subject: [PATCH 20/21] Fix Testcases --- yaksh/test_views.py | 4 ++-- yaksh/views.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/yaksh/test_views.py b/yaksh/test_views.py index df426acca..8f503f9e0 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -3728,7 +3728,7 @@ def test_view_course_status(self): self.assertEqual(response.status_code, 200) self.assertTrue(response.context['is_progress']) self.assertEqual(response.context['course'], self.user1_course) - student_details = response.context['student_details'][0] + student_details = response.context['stud_details'][0] student, grade, percent, current_unit = student_details self.assertEqual(student.username, "demo_student") self.assertEqual(grade, "NA") @@ -3743,7 +3743,7 @@ def test_view_course_status(self): self.assertEqual(response.status_code, 200) self.assertTrue(response.context['is_progress']) self.assertEqual(response.context['course'], self.user1_course) - student_details = response.context['student_details'][0] + student_details = response.context['stud_details'][0] student, grade, percent, current_unit = student_details self.assertEqual(student.username, "demo_student") self.assertIsNone(grade) diff --git a/yaksh/views.py b/yaksh/views.py index 272184d0c..9181d05ea 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -2326,9 +2326,9 @@ def download_course_csv(request, course_id): "id", "first_name", "last_name", "email", "institute", "roll_number" )) que_pprs = [ - quiz.questionpaper_set.values( + unit.quiz.questionpaper_set.values( "id", "quiz__description", "total_marks")[0] - for quiz in course.get_quizzes() + for unit in course.get_quizzes() if unit.quiz ] total_course_marks = sum([qp.get("total_marks", 0) for qp in que_pprs]) qp_ids = [ @@ -3430,7 +3430,7 @@ def get_user_data(request, course_id, student_id): ] data['modules'] = module_percent _update_course_percent(course, student) - data['course_percentage'] = course.get_completion_percent(student) + data['course_percentage'] = course.get_completion_percent(student, course_status) data['student'] = student template_path = os.path.join( os.path.dirname(__file__), "templates", "yaksh", "user_status.html" From ac78da65a87dc187caef9a20dbb2df33ad0c84a8 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 28 Jun 2021 16:11:55 +0530 Subject: [PATCH 21/21] Fix tests --- yaksh/models.py | 16 ++++++------- yaksh/test_models.py | 57 ++++++++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index b49278f17..754dafb7e 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1238,17 +1238,17 @@ def set_grade(self, course_status, module_learning_units): self.save() def calculate_percentage(self, course_status, module_learning_units): - quizzes = self.course.get_quizzes() - if self.is_course_complete(course_status, module_learning_units) and quizzes: + units = self.course.get_quizzes() + if self.is_course_complete(course_status, module_learning_units) and units: total_weightage = 0 sum = 0 - for quiz in quizzes: - total_weightage += quiz.weightage + for unit in units: + total_weightage += unit.quiz.weightage marks = AnswerPaper.objects.get_user_best_of_attempts_marks( - quiz, self.user.id, self.course.id) - out_of = quiz.questionpaper_set.first().total_marks - sum += (marks/out_of)*quiz.weightage - self.percentage = (sum/total_weightage)*100 + unit.quiz, self.user.id, self.course.id) + out_of = unit.quiz.questionpaper_set.first().total_marks + sum += (marks / out_of) * unit.quiz.weightage + self.percentage = (sum / total_weightage) * 100 self.save() def is_course_complete(self, course_status, module_learning_units): diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 9fac71e61..e49f55aab 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -353,12 +353,8 @@ def test_prerequisite_passes(self): ) def test_get_quiz_units(self): - # Given - quizzes = [self.quiz] - # When - module_quizzes = self.learning_module.get_quiz_units() - # Then - self.assertSequenceEqual(module_quizzes, quizzes) + module_quizzes = self.learning_module.get_quiz_units().first().quiz + self.assertEqual(module_quizzes, self.quiz) def test_get_learning_units(self): # Given @@ -850,22 +846,44 @@ def tearDown(self): self.question_paper3.delete() def test_get_total_students(self): - self.assertEqual(self.quiz3.get_total_students(self.course), 2) + total_students = self.quiz3.get_total_students( + self.course + ).distinct().count() + self.assertEqual(total_students, 2) def test_get_total_students_without_questionpaper(self): - self.assertEqual(self.quiz4.get_total_students(self.course), 0) + total_students = self.quiz4.get_total_students( + self.course + ).distinct().count() + self.assertEqual(total_students, 0) def test_get_passed_students(self): - self.assertEqual(self.quiz3.get_passed_students(self.course), 1) + total_students = self.quiz3.get_total_students(self.course) + passed_students = total_students.filter( + passed=True + ).distinct().count() + self.assertEqual(passed_students, 1) def test_get_passed_students_without_questionpaper(self): - self.assertEqual(self.quiz4.get_passed_students(self.course), 0) + total_students = self.quiz4.get_total_students(self.course) + passed_students = total_students.filter( + passed=True + ).distinct().count() + self.assertEqual(passed_students, 0) def test_get_failed_students(self): - self.assertEqual(self.quiz3.get_failed_students(self.course), 1) + total_students = self.quiz3.get_total_students(self.course) + failed_students = total_students.filter( + passed=False + ).distinct().count() + self.assertEqual(failed_students, 1) def test_get_failed_students_without_questionpaper(self): - self.assertEqual(self.quiz4.get_failed_students(self.course), 0) + total_students = self.quiz4.get_total_students(self.course) + failed_students = total_students.filter( + passed=False + ).distinct().count() + self.assertEqual(failed_students, 0) def test_quiz(self): """ Test Quiz""" @@ -1999,12 +2017,8 @@ def test_get_learning_modules(self): self.assertSequenceEqual(list(course_modules), modules) def test_get_quizzes(self): - # Given - quizzes = [self.quiz1] - # When - course_quizzes = self.course.get_quizzes() - # Then - self.assertSequenceEqual(course_quizzes, quizzes) + course_quizzes = self.course.get_quizzes()[1].quiz + self.assertEqual(course_quizzes, self.quiz1) def test_get_learning_units(self): # Given @@ -2386,7 +2400,6 @@ def test_course_is_complete(self): ) # When - # print(self.module_learning_units) self.course_status.completed_units.add(self.unit_1_quiz) # Then self.assertFalse(self.course_status.is_course_complete( @@ -2435,7 +2448,11 @@ def test_course_is_complete(self): self.assertEqual(self.course_status.get_grade(), 'B') # Test get course grade after completion - self.assertEqual(self.course.get_grade(self.answerpaper1.user), 'B') + self.assertEqual( + self.course.get_grade( + self.answerpaper1.user, self.course_status + ), 'B' + ) class FileUploadTestCases(TestCase):