summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKing2019-04-09 17:26:49 +0530
committerGitHub2019-04-09 17:26:49 +0530
commit82f1fa9f778d85619343bbb79b9faec41696261f (patch)
treeada2ee83c333ab6fa2cab5b09e94588ab6ab2aa3
parent0c8b272aa25210d71e03715c1209402d2b770a98 (diff)
parent54e674c12704013377b9dd6b6c82df526f4e1cdb (diff)
downloadonline_test-82f1fa9f778d85619343bbb79b9faec41696261f.tar.gz
online_test-82f1fa9f778d85619343bbb79b9faec41696261f.tar.bz2
online_test-82f1fa9f778d85619343bbb79b9faec41696261f.zip
Merge pull request #592 from ankitjavalkar/add-prereq-passing-check
Add functionality to restrict access to next module based on passing previous module
-rw-r--r--yaksh/models.py49
-rw-r--r--yaksh/templates/yaksh/design_course_session.html25
-rw-r--r--yaksh/test_models.py49
-rw-r--r--yaksh/test_views.py2
-rw-r--r--yaksh/views.py42
5 files changed, 154 insertions, 13 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 1d6bb89..eb18bb7 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
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">&nbsp;</th>
@@ -88,6 +95,8 @@
<td>&nbsp;</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 4c1f5b9..ee7c911 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 9199a3a..d634e0c 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):
@@ -2442,17 +2450,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,
@@ -2714,13 +2729,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)
@@ -2752,11 +2774,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