summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorankitjavalkar2019-02-18 11:45:07 +0530
committerankitjavalkar2019-03-12 18:41:09 +0530
commit0df9abf2dce51ed0b1f8247f91f0fe4c039bc14b (patch)
treefda80884d1e1658b00a69c2eea15f98ad9f128b7
parent34a8dcac95c215432a32662310648f69f6dc504a (diff)
downloadonline_test-0df9abf2dce51ed0b1f8247f91f0fe4c039bc14b.tar.gz
online_test-0df9abf2dce51ed0b1f8247f91f0fe4c039bc14b.tar.bz2
online_test-0df9abf2dce51ed0b1f8247f91f0fe4c039bc14b.zip
Add functionality to restrict access to next module based on passing previous module
-rw-r--r--yaksh/models.py47
-rw-r--r--yaksh/templates/yaksh/design_course_session.html25
-rw-r--r--yaksh/views.py36
3 files changed, 98 insertions, 10 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index cce90e7..5f72ecf 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 ans_ppr.first().passed
+ 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,33 @@ class LearningModule(models.Model):
success = False
return success
+ def get_passing_status(self, user, course):
+ course_status = CourseStatus.objects.filter(user=user, course=course)
+ state = "failed"
+ if course_status.exists():
+ ordered_units = self.learning_unit.filter(type='quiz').order_by("order")
+
+ status_list = [unit.quiz.get_answerpaper_passing_status(user, course)
+ for unit in ordered_units]
+
+ if not status_list:
+ status = False
+ else:
+ status = all(status_list)
+ 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/views.py b/yaksh/views.py
index 6c7a12e..5009cb6 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -471,11 +471,17 @@ 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)
@@ -501,7 +507,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):
@@ -2424,17 +2430,22 @@ 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,
@@ -2696,13 +2707,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)
@@ -2734,11 +2752,17 @@ 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