summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/templates/yaksh/show_video.html19
-rw-r--r--yaksh/test_views.py69
-rw-r--r--yaksh/urls.py2
-rw-r--r--yaksh/views.py55
4 files changed, 119 insertions, 26 deletions
diff --git a/yaksh/templates/yaksh/show_video.html b/yaksh/templates/yaksh/show_video.html
index f4b59ac..17f9d86 100644
--- a/yaksh/templates/yaksh/show_video.html
+++ b/yaksh/templates/yaksh/show_video.html
@@ -64,6 +64,7 @@
{% if learning_module.html_data%}
<hr>
{% endif %}
+ {% if learning_module.get_learning_units %}
<center><h4>Following are the units in this modules</h4></center>
<table class="table">
<tr>
@@ -95,13 +96,23 @@
</tr>
{% endfor %}
</table>
+ {% else %}
+ <center><h3>No Lessons/Quizzes Found</h3></center>
+ {% endif %}
</div>
</div>
<div style="text-align: center;">
- <a href="{{ URL_ROOT }}/exam/next_unit/{{course.id}}/{{learning_module.id}}/{{first_unit.id}}/1" class="btn btn-info">Start
- <span class="glyphicon glyphicon-chevron-right">
- </span>
- </a>
+ {% if first_unit %}
+ <a href="{{ URL_ROOT }}/exam/next_unit/{{course.id}}/{{learning_module.id}}/{{first_unit.id}}/1" class="btn btn-info">Start
+ <span class="glyphicon glyphicon-chevron-right">
+ </span>
+ </a>
+ {% else %}
+ <a href="{{ URL_ROOT }}/exam/next_unit/{{course.id}}/{{learning_module.id}}" class="btn btn-info">Next
+ <span class="glyphicon glyphicon-chevron-right">
+ </span>
+ </a>
+ {% endif %}
</div>
{% else %}
<div class="panel panel-default" style="border: none; box-shadow: none;">
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 0b43079..9be8d13 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -4604,6 +4604,7 @@ class TestLearningModule(TestCase):
check_prerequisite=False, creator=self.user)
self.course.teachers.add(self.teacher)
self.course.learning_module.add(self.learning_module)
+ self.course.learning_module.add(self.learning_module1)
self.expected_url = "/exam/manage/courses/all_learning_module/"
@@ -4868,13 +4869,35 @@ class TestLearningModule(TestCase):
self.assertEqual(response.context["current_unit"].id,
self.learning_unit1.id)
+ # Go to next module with empty module
+ response = self.client.get(
+ reverse('yaksh:next_unit',
+ kwargs={"module_id": self.learning_module1.id,
+ "course_id": self.course.id}),
+ follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context["state"], "module")
+ self.assertEqual(response.context["learning_module"].id,
+ self.learning_module.id)
+
+ # Go to next module from last unit of previous unit
+ response = self.client.get(
+ reverse('yaksh:next_unit',
+ kwargs={"module_id": self.learning_module.id,
+ "course_id": self.course.id,
+ "current_unit_id": self.learning_unit1.id}),
+ follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context["state"], "module")
+ self.assertEqual(response.context["learning_module"].id,
+ self.learning_module1.id)
+
class TestLessons(TestCase):
def setUp(self):
self.client = Client()
self.mod_group = Group.objects.create(name='moderator')
- tzone = pytz.timezone('UTC')
# Create Moderator with profile
self.user_plaintext_pass = 'demo'
self.user = User.objects.create_user(
@@ -4922,25 +4945,30 @@ class TestLessons(TestCase):
name="Python Course",
enrollment="Open Enrollment", creator=self.user)
- self.quiz = Quiz.objects.create(
- start_date_time=datetime(2014, 10, 9, 10, 8, 15, 0, tzone),
- end_date_time=datetime(2015, 10, 9, 10, 8, 15, 0, tzone),
- duration=30, active=True, instructions="Demo Instructions",
- attempts_allowed=-1, time_between_attempts=0,
- description='demo quiz', pass_criteria=40,
- creator=self.user
- )
-
self.lesson = Lesson.objects.create(
name="test lesson", description="test description",
creator=self.user)
+ self.lesson2 = Lesson.objects.create(
+ name="test lesson2", description="test description2",
+ creator=self.user)
self.learning_unit = LearningUnit.objects.create(
- order=0, type="lesson", lesson=self.lesson)
+ order=0, type="lesson", lesson=self.lesson
+ )
+ self.learning_unit2 = LearningUnit.objects.create(
+ order=0, type="lesson", lesson=self.lesson2
+ )
self.learning_module = LearningModule.objects.create(
order=0, name="test module", description="module",
- check_prerequisite=False, creator=self.user)
+ check_prerequisite=False, creator=self.user
+ )
+ self.learning_module2 = LearningModule.objects.create(
+ order=1, name="test module 2", description="module 2",
+ check_prerequisite=True, creator=self.user
+ )
self.learning_module.learning_unit.add(self.learning_unit.id)
- self.course.learning_module.add(self.learning_module.id)
+ self.learning_module2.learning_unit.add(self.learning_unit2.id)
+ self.course.learning_module.add(*[
+ self.learning_module.id, self.learning_module2.id])
self.course.teachers.add(self.teacher.id)
self.expected_url = "/exam/manage/courses/"
@@ -4949,11 +4977,13 @@ class TestLessons(TestCase):
self.user.delete()
self.student.delete()
self.teacher.delete()
- self.quiz.delete()
self.course.delete()
self.learning_unit.delete()
+ self.learning_unit2.delete()
self.learning_module.delete()
+ self.learning_module2.delete()
self.lesson.delete()
+ self.lesson2.delete()
def test_edit_lesson_denies_non_moderator(self):
""" Student should not be allowed to edit lesson """
@@ -5038,6 +5068,17 @@ class TestLessons(TestCase):
self.assertEqual(response.context["state"], "lesson")
self.assertEqual(response.context["current_unit"], self.learning_unit)
+ # Check unit module prerequisite completion status
+ response = self.client.get(
+ reverse('yaksh:show_lesson',
+ kwargs={"lesson_id": self.lesson2.id,
+ "module_id": self.learning_module2.id,
+ "course_id": self.course.id}))
+ err_msg = "You have not completed the module previous to {0}".format(
+ self.learning_module2.name)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context["msg"], err_msg)
+
def test_show_all_lessons(self):
""" Moderator should be able to see all created lessons"""
self.client.login(
diff --git a/yaksh/urls.py b/yaksh/urls.py
index 1357279..08c2091 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -40,6 +40,8 @@ urlpatterns = [
views.view_module, name='view_module'),
url(r'^next_unit/(?P<course_id>\d+)/(?P<module_id>\d+)/(?P<current_unit_id>\d+)/$',
views.get_next_unit, name='next_unit'),
+ url(r'^next_unit/(?P<course_id>\d+)/(?P<module_id>\d+)/$',
+ views.get_next_unit, name='next_unit'),
url(r'^next_unit/(?P<course_id>\d+)/(?P<module_id>\d+)/(?P<current_unit_id>\d+)/(?P<first_unit>\d+)/$',
views.get_next_unit, name='next_unit'),
url(r'^course_modules/(?P<course_id>\d+)/$',
diff --git a/yaksh/views.py b/yaksh/views.py
index 98cd010..2bc5dfe 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -475,6 +475,16 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None,
learning_module = course.learning_module.get(id=module_id)
learning_unit = learning_module.learning_unit.get(quiz=quest_paper.quiz.id)
+ # unit module prerequiste check
+ if learning_module.has_prerequisite():
+ if not learning_module.is_prerequisite_passed(user, course):
+ msg = "You have not completed the module previous to {0}".format(
+ learning_module.name)
+ return course_modules(request, course_id, msg)
+
+ # update course status with current unit
+ _update_unit_status(course_id, user, learning_unit)
+
# is user enrolled in the course
if not course.is_enrolled(user):
msg = 'You are not enrolled in {0} course'.format(course.name)
@@ -2338,6 +2348,15 @@ def show_lesson(request, lesson_id, module_id, course_id):
learn_module = course.learning_module.get(id=module_id)
learn_unit = learn_module.learning_unit.get(lesson_id=lesson_id)
learning_units = learn_module.get_learning_units()
+ if learn_module.has_prerequisite():
+ if not learn_module.is_prerequisite_passed(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)
+
+ # 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):
@@ -2514,7 +2533,7 @@ def preview_html_text(request):
@login_required
@email_verified
-def get_next_unit(request, course_id, module_id, current_unit_id,
+def get_next_unit(request, course_id, module_id, current_unit_id=None,
first_unit=None):
user = request.user
course = Course.objects.prefetch_related("learning_module").get(
@@ -2523,8 +2542,14 @@ def get_next_unit(request, course_id, module_id, current_unit_id,
raise Http404('You are not enrolled for this course!')
learning_module = course.learning_module.prefetch_related(
"learning_unit").get(id=module_id)
- current_learning_unit = learning_module.learning_unit.get(
- id=current_unit_id)
+
+ if current_unit_id:
+ current_learning_unit = learning_module.learning_unit.get(
+ id=current_unit_id)
+ else:
+ next_module = course.next_module(learning_module.id)
+ return my_redirect("/exam/quizzes/view_module/{0}/{1}".format(
+ next_module.id, course_id))
if first_unit:
next_unit = current_learning_unit
@@ -2553,9 +2578,6 @@ def get_next_unit(request, course_id, module_id, current_unit_id,
return my_redirect("/exam/quizzes/view_module/{0}/{1}/".format(
next_module.id, course.id))
- # make next available unit as current unit
- course_status.current_unit = next_unit
- course_status.save()
if next_unit.type == "quiz":
return my_redirect("/exam/start/{0}/{1}/{2}".format(
next_unit.quiz.questionpaper_set.get().id, module_id, course_id))
@@ -2641,13 +2663,14 @@ def view_module(request, module_id, course_id, msg=None):
all_modules = course.get_learning_modules()
if learning_module.has_prerequisite():
if not learning_module.is_prerequisite_passed(user, course):
- msg = "You have not completed the previous learning module"
+ msg = "You have not completed 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
- context['first_unit'] = learning_units[0]
+ context['first_unit'] = learning_units.first()
context['all_modules'] = all_modules
context['user'] = user
context['course'] = course
@@ -2689,3 +2712,19 @@ def course_status(request, course_id):
'state': 'course_status', 'modules': course.get_learning_modules()
}
return my_render_to_response('yaksh/course_detail.html', context)
+
+
+def _update_unit_status(course_id, user, unit):
+ """ Update course status with current unit """
+ course_status = CourseStatus.objects.filter(
+ user=user, course_id=course_id,
+ )
+ if not course_status.exists():
+ course_status = CourseStatus.objects.create(
+ user=user, course_id=course_id
+ )
+ else:
+ course_status = course_status.first()
+ # make next available unit as current unit
+ course_status.current_unit = unit
+ course_status.save()