diff options
-rw-r--r-- | yaksh/models.py | 51 | ||||
-rw-r--r-- | yaksh/templates/yaksh/design_course_session.html | 25 | ||||
-rw-r--r-- | yaksh/test_models.py | 49 | ||||
-rw-r--r-- | yaksh/test_views.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 42 |
5 files changed, 155 insertions, 14 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 1d6bb89..d0161c1 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -539,6 +539,18 @@ class Quiz(models.Model): status = "not attempted" return status + def get_answerpaper_passing_status(self, user, course): + try: + qp = self.questionpaper_set.get().id + except QuestionPaper.DoesNotExist: + qp = None + ans_ppr = AnswerPaper.objects.filter( + user=user, course=course, question_paper=qp + ).order_by("-attempt_number") + if ans_ppr.exists(): + return any([paper.passed for paper in ans_ppr]) + return False + def _create_quiz_copy(self, user): question_papers = self.questionpaper_set.all() new_quiz = self @@ -586,7 +598,7 @@ class LearningUnit(models.Model): def has_prerequisite(self): return self.check_prerequisite - def is_prerequisite_passed(self, user, learning_module, course): + def is_prerequisite_complete(self, user, learning_module, course): ordered_units = learning_module.learning_unit.order_by("order") ordered_units_ids = list(ordered_units.values_list("id", flat=True)) current_unit_index = ordered_units_ids.index(self.id) @@ -624,6 +636,7 @@ class LearningModule(models.Model): order = models.IntegerField(default=0) creator = models.ForeignKey(User, related_name="module_creator") check_prerequisite = models.BooleanField(default=True) + check_prerequisite_passes = models.BooleanField(default=False) html_data = models.TextField(null=True, blank=True) active = models.BooleanField(default=True) is_trial = models.BooleanField(default=False) @@ -653,6 +666,9 @@ class LearningModule(models.Model): def toggle_check_prerequisite(self): self.check_prerequisite = not self.check_prerequisite + def toggle_check_prerequisite_passes(self): + self.check_prerequisite_passes = not self.check_prerequisite_passes + def get_next_unit(self, current_unit_id): ordered_units = self.learning_unit.order_by("order") ordered_units_ids = list(ordered_units.values_list("id", flat=True)) @@ -680,7 +696,7 @@ class LearningModule(models.Model): default_status = "inprogress" return default_status - def is_prerequisite_passed(self, user, course): + def is_prerequisite_complete(self, user, course): """ Check if prerequisite module is completed """ ordered_modules = course.learning_module.order_by("order") ordered_modules_ids = list(ordered_modules.values_list( @@ -698,6 +714,35 @@ class LearningModule(models.Model): success = False return success + def get_passing_status(self, user, course): + course_status = CourseStatus.objects.filter(user=user, course=course) + if course_status.exists(): + learning_units_with_quiz = self.learning_unit.filter(type='quiz') + ordered_units = learning_units_with_quiz.order_by("order") + + statuses = [ + unit.quiz.get_answerpaper_passing_status(user, course) + for unit in ordered_units + ] + + if not statuses: + status = False + else: + status = all(statuses) + return status + + def is_prerequisite_passed(self, user, course): + """ Check if prerequisite module is passed """ + ordered_modules = course.learning_module.order_by("order") + if ordered_modules.first() == self: + return True + else: + if self.order == 0: + return True + prev_module = ordered_modules.get(order=self.order-1) + status = prev_module.get_passing_status(user, course) + return status + def has_prerequisite(self): return self.check_prerequisite @@ -1103,7 +1148,7 @@ class Profile(models.Model): def get_user_dir(self): """Return the output directory for the user.""" - user_dir = join(settings.OUTPUT_DIR, str(self.user.username)) + user_dir = join(settings.OUTPUT_DIR, str(self.user.id)) if not exists(user_dir): os.makedirs(user_dir) os.chmod(user_dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) diff --git a/yaksh/templates/yaksh/design_course_session.html b/yaksh/templates/yaksh/design_course_session.html index 2deb95f..700d71c 100644 --- a/yaksh/templates/yaksh/design_course_session.html +++ b/yaksh/templates/yaksh/design_course_session.html @@ -74,13 +74,20 @@ <th width="5%">Select</th> <th>Module</th> <th width="20%">Order</th> - <th width="25%" colspan="2">Check Prerequisite + <th width="25%" colspan="2">Check Prerequisite Completion <br> <a href="#" data-toggle="tooltip" id="prereq_msg"> <span class="glyphicon glyphicon-question-sign"> </span> What's This </a> </th> + <th width="25%" colspan="2">Check Prerequisite Passing + <br> + <a href="#" data-toggle="tooltip" id="prereq_passing_msg"> + <span class="glyphicon glyphicon-question-sign"> + </span> What's This + </a> + </th> </tr> <tr> <th scope="row"> </th> @@ -88,6 +95,8 @@ <td> </td> <th>Currently</th> <th>Change</th> + <th>Currently</th> + <th>Change</th> </tr> {% for module in added_learning_modules %} <tr> @@ -109,6 +118,16 @@ <td> <input type="checkbox" name="check_prereq" value="{{module.id}}"> </td> + <td> + {% if module.check_prerequisite_passes %} + Yes + {% else %} + No + {% endif %} + </td> + <td> + <input type="checkbox" name="check_prereq_passes" value="{{module.id}}"> + </td> </ul> </tr> {% endfor %} @@ -119,7 +138,9 @@ <center> <button id="Remove" name="Remove" class="btn btn-danger" type="submit">Remove from course</button> <button id="Change" name="Change" class="btn btn-info" type="submit"> Change Order</button> - <button id="Change" name="Change_prerequisite" class="btn btn-primary" type="submit"> Change Prerequisite</button> + <button id="Change" name="change_prerequisite_completion" class="btn btn-primary" type="submit"> Change Prerequisite Completion</button> + <button id="Change_prereq_passing" name="change_prerequisite_passing" class="btn btn-primary" type="submit"> Change Prerequisite Passing</button> + </center> </div> </div> <!-- /.row --> diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 374fb29..4d91b27 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -146,14 +146,52 @@ class LearningModuleTestCases(unittest.TestCase): self.learning_module_two = LearningModule.objects.get(name='LM2') self.creator = User.objects.get(username='creator') self.student = User.objects.get(username='course_user') - self.learning_unit_one = LearningUnit.objects.get(order=1) - self.learning_unit_two = LearningUnit.objects.get(order=2) + self.learning_unit_one = LearningUnit.objects.get(id=1) + self.learning_unit_two = LearningUnit.objects.get(id=2) self.quiz = Quiz.objects.get(description='demo quiz 1') self.lesson = Lesson.objects.get(name='L1') self.course = Course.objects.get(name='Python Course') self.course_status = CourseStatus.objects.get( course=self.course, user=self.student) + self.prereq_course = Course.objects.create( + name="Prerequisite Course", + enrollment="Enroll Request", creator=self.creator + ) + + self.prereq_learning_module = LearningModule.objects.create( + name='LM3', description='module one', creator=self.creator + ) + self.test_learning_module = LearningModule.objects.create( + name='LM4', description='module two', + creator=self.creator, order=1 + ) + course_status = CourseStatus.objects.create( + course=self.prereq_course, user=self.student + ) + lesson = Lesson.objects.create( + name='P1', description='Video Lesson', + creator=self.creator + ) + learning_unit_lesson = LearningUnit.objects.create( + order=2, + lesson=lesson, + type='lesson' + ) + learning_unit_quiz = LearningUnit.objects.create( + order=1, + quiz=self.quiz, + type='quiz' + ) + self.prereq_learning_module.learning_unit.add(learning_unit_quiz) + self.prereq_learning_module.learning_unit.add(learning_unit_lesson) + self.prereq_learning_module.save() + self.prereq_course.learning_module.add(self.prereq_learning_module) + self.prereq_course.learning_module.add(self.test_learning_module) + self.prereq_course.students.add(self.student) + self.prereq_course.save() + + def tearDown(self): # Remove unit from course status completed units self.course_status.completed_units.remove(self.learning_unit_one) @@ -165,6 +203,13 @@ class LearningModuleTestCases(unittest.TestCase): self.assertTrue(self.learning_module.check_prerequisite) self.assertEqual(self.learning_module.order, 0) + def test_prerequisite_passes(self): + self.assertFalse( + self.test_learning_module.is_prerequisite_passed( + self.student, self.prereq_course + ) + ) + def test_get_quiz_units(self): # Given quizzes = [self.quiz] diff --git a/yaksh/test_views.py b/yaksh/test_views.py index d98435d..714fc67 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -1937,7 +1937,7 @@ class TestCourses(TestCase): # Create a learning module to add to course self.learning_module = LearningModule.objects.create( order=0, name="test module", description="module", - check_prerequisite=False, creator=self.teacher) + check_prerequisite=True, creator=self.teacher) self.user1_course = Course.objects.create( name="Python Course", diff --git a/yaksh/views.py b/yaksh/views.py index ef18148..7202826 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -484,11 +484,19 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, # unit module prerequiste check if learning_module.has_prerequisite(): - if not learning_module.is_prerequisite_passed(user, course): + if not learning_module.is_prerequisite_complete(user, course): msg = "You have not completed the module previous to {0}".format( learning_module.name) return course_modules(request, course_id, msg) + if learning_module.check_prerequisite_passes: + if not learning_module.is_prerequisite_passed(user, course): + msg = ( + "You have not successfully passed the module" + " previous to {0}".format(learning_module.name) + ) + return course_modules(request, course_id, msg) + # is user enrolled in the course if not course.is_enrolled(user): msg = 'You are not enrolled in {0} course'.format(course.name) @@ -514,7 +522,7 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, # prerequisite check and passing criteria for quiz if learning_unit.has_prerequisite(): - if not learning_unit.is_prerequisite_passed( + if not learning_unit.is_prerequisite_complete( user, learning_module, course): msg = "You have not completed the previous Lesson/Quiz/Exercise" if is_moderator(user): @@ -2441,17 +2449,24 @@ def show_lesson(request, lesson_id, module_id, course_id): msg = "{0} is not active".format(learn_unit.lesson.name) return view_module(request, module_id, course_id, msg) if learn_module.has_prerequisite(): - if not learn_module.is_prerequisite_passed(user, course): + if not learn_module.is_prerequisite_complete(user, course): msg = "You have not completed the module previous to {0}".format( learn_module.name) return view_module(request, module_id, course_id, msg) + if learn_module.check_prerequisite_passes: + if not learn_module.is_prerequisite_passed(user, course): + msg = ( + "You have not successfully passed the module" + " previous to {0}".format(learn_module.name) + ) + return view_module(request, module_id, course_id, msg) # update course status with current unit _update_unit_status(course_id, user, learn_unit) all_modules = course.get_learning_modules() if learn_unit.has_prerequisite(): - if not learn_unit.is_prerequisite_passed(user, learn_module, course): + if not learn_unit.is_prerequisite_complete(user, learn_module, course): msg = "You have not completed previous Lesson/Quiz/Exercise" return view_module(request, learn_module.id, course_id, msg=msg) context = {'lesson': learn_unit.lesson, 'user': user, @@ -2713,13 +2728,20 @@ def design_course(request, course_id): if remove_values: course.learning_module.remove(*remove_values) - if "Change_prerequisite" in request.POST: + if "change_prerequisite_completion" in request.POST: unit_list = request.POST.getlist("check_prereq") for unit in unit_list: learning_module = course.learning_module.get(id=unit) learning_module.toggle_check_prerequisite() learning_module.save() + if "change_prerequisite_passing" in request.POST: + unit_list = request.POST.getlist("check_prereq_passes") + for unit in unit_list: + learning_module = course.learning_module.get(id=unit) + learning_module.toggle_check_prerequisite_passes() + learning_module.save() + added_learning_modules = course.get_learning_modules() all_learning_modules = LearningModule.objects.filter( creator=user, is_trial=False) @@ -2751,11 +2773,19 @@ def view_module(request, module_id, course_id, msg=None): return course_modules(request, course_id, msg) all_modules = course.get_learning_modules() if learning_module.has_prerequisite(): - if not learning_module.is_prerequisite_passed(user, course): + if not learning_module.is_prerequisite_complete(user, course): msg = "You have not completed the module previous to {0}".format( learning_module.name) return course_modules(request, course_id, msg) + if learning_module.check_prerequisite_passes: + if not learning_module.is_prerequisite_passed(user, course): + msg = ( + "You have not successfully passed the module" + " previous to {0}".format(learning_module.name) + ) + return course_modules(request, course_id, msg) + learning_units = learning_module.get_learning_units() context['learning_units'] = learning_units context['learning_module'] = learning_module |