From 67d4f84d3274ffce449073d1209f29943cfccf06 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Tue, 16 Jan 2018 16:23:42 +0530
Subject: Change template, urls.py, views.py
- Change show_video.html to empty module
- Add condition to check if module is completed for the corresponding unit
---
yaksh/templates/yaksh/show_video.html | 19 +++++++++---
yaksh/urls.py | 2 ++
yaksh/views.py | 54 +++++++++++++++++++++++++++++------
3 files changed, 63 insertions(+), 12 deletions(-)
(limited to 'yaksh')
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%}
{% endif %}
+ {% if learning_module.get_learning_units %}
Following are the units in this modules
@@ -95,13 +96,23 @@
{% endfor %}
+ {% else %}
+ No Lessons/Quizzes Found
+ {% endif %}
{% else %}
diff --git a/yaksh/urls.py b/yaksh/urls.py
index d60a5d3..7eca5af 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\d+)/(?P\d+)/(?P\d+)/$',
views.get_next_unit, name='next_unit'),
+ url(r'^next_unit/(?P\d+)/(?P\d+)/$',
+ views.get_next_unit, name='next_unit'),
url(r'^next_unit/(?P\d+)/(?P\d+)/(?P\d+)/(?P\d+)/$',
views.get_next_unit, name='next_unit'),
url(r'^course_modules/(?P\d+)/$',
diff --git a/yaksh/views.py b/yaksh/views.py
index 7049912..3b7d28d 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -477,6 +477,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)
@@ -2332,6 +2342,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):
@@ -2508,7 +2527,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(
@@ -2517,8 +2536,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
@@ -2547,9 +2572,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))
@@ -2635,13 +2657,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
@@ -2683,3 +2706,18 @@ 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):
+ 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()
--
cgit
From 1c9749a5fbbbebe8757358a9d1ef36caa894e399 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Tue, 16 Jan 2018 16:26:10 +0530
Subject: Add test to check if module is completed at unit level
---
yaksh/test_views.py | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 343e043..42e14b5 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -4745,7 +4745,6 @@ class TestLessons(TestCase):
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(
@@ -4793,25 +4792,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/"
@@ -4820,11 +4824,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 """
@@ -4909,6 +4915,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(
--
cgit
From bc8185f48856c30a37c4c80b0541bebbae2285a2 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Thu, 18 Jan 2018 16:05:24 +0530
Subject: Add docstring to update course status view function
---
yaksh/views.py | 1 +
1 file changed, 1 insertion(+)
(limited to 'yaksh')
diff --git a/yaksh/views.py b/yaksh/views.py
index 3b7d28d..637b35c 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -2709,6 +2709,7 @@ def course_status(request, course_id):
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,
)
--
cgit
From 1ab5018b89f6d566471eba26b1d206b1b142b8a0 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Fri, 19 Jan 2018 12:58:26 +0530
Subject: Improve views test cases for lessons bug
---
yaksh/test_views.py | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'yaksh')
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 42e14b5..ff2b5a7 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -4475,6 +4475,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/"
@@ -4739,6 +4740,29 @@ 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):
--
cgit