diff options
-rw-r--r-- | yaksh/forms.py | 2 | ||||
-rw-r--r-- | yaksh/live_server_tests/selenium_test.py | 2 | ||||
-rw-r--r-- | yaksh/models.py | 12 | ||||
-rw-r--r-- | yaksh/templates/404.html | 8 | ||||
-rw-r--r-- | yaksh/templates/yaksh/complete.html | 7 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 10 | ||||
-rw-r--r-- | yaksh/templates/yaksh/design_questionpaper.html | 9 | ||||
-rw-r--r-- | yaksh/test_models.py | 44 | ||||
-rw-r--r-- | yaksh/test_views.py | 24 | ||||
-rw-r--r-- | yaksh/views.py | 18 |
10 files changed, 114 insertions, 22 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index 9fd2eaa..258a1ee 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -339,4 +339,4 @@ class LearningModuleForm(forms.ModelForm): class Meta: model = LearningModule - fields = ['name', 'description'] + fields = ['name', 'description', 'active'] diff --git a/yaksh/live_server_tests/selenium_test.py b/yaksh/live_server_tests/selenium_test.py index 5635add..6351f9e 100644 --- a/yaksh/live_server_tests/selenium_test.py +++ b/yaksh/live_server_tests/selenium_test.py @@ -152,7 +152,7 @@ class SeleniumTest(): def close_quiz(self): quit_link_elem = WebDriverWait(self.driver, 5).until( - EC.presence_of_element_located((By.ID, "home")) + EC.presence_of_element_located((By.ID, "Next")) ) quit_link_elem.click() diff --git a/yaksh/models.py b/yaksh/models.py index 93e656a..f065190 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -154,6 +154,9 @@ class Lesson(models.Model): # Creator of the lesson creator = models.ForeignKey(User) + # Activate/Deactivate Lesson + active = models.BooleanField(default=True) + def __str__(self): return "{0}".format(self.name) @@ -425,6 +428,7 @@ class LearningModule(models.Model): creator = models.ForeignKey(User, related_name="module_creator") check_prerequisite = models.BooleanField(default=True) html_data = models.TextField(null=True, blank=True) + active = models.BooleanField(default=True) is_trial = models.BooleanField(default=False) def get_quiz_units(self): @@ -458,7 +462,7 @@ class LearningModule(models.Model): return ordered_units.get(id=ordered_units_ids[next_index]) def get_status(self, user, course): - """ Get module status if it completed, inprogress or not attempted""" + """ Get module status if completed, inprogress or not attempted""" learning_module = course.learning_module.prefetch_related( "learning_unit").get(id=self.id) ordered_units = learning_module.learning_unit.order_by("order") @@ -469,10 +473,10 @@ class LearningModule(models.Model): default_status = "no units" elif all([status == "completed" for status in status_list]): default_status = "completed" - elif "inprogress" in status_list: - default_status = "inprogress" - else: + elif all([status == "not attempted" for status in status_list]): default_status = "not attempted" + else: + default_status = "inprogress" return default_status def is_prerequisite_passed(self, user, course): diff --git a/yaksh/templates/404.html b/yaksh/templates/404.html index e9d99de..d4777f2 100644 --- a/yaksh/templates/404.html +++ b/yaksh/templates/404.html @@ -1,7 +1,13 @@ {% extends "base.html" %} +{% block pagetitle %} <h2>Yaksh</h2> {% endblock %} + {% block content %} +<center> It seems that you have encountered an error -Type of Error - {{ exception }} +<br> Please contact your administrator +<br><br> +<div class="alert alert-danger">Error Message:- {{exception}}</div> +</center> {% endblock %} diff --git a/yaksh/templates/yaksh/complete.html b/yaksh/templates/yaksh/complete.html index e4317fe..3d6cadc 100644 --- a/yaksh/templates/yaksh/complete.html +++ b/yaksh/templates/yaksh/complete.html @@ -36,19 +36,20 @@ width="80" alt="YAKSH"></img>{% endblock %} {% if not module_id %} <br><center><h4>You may now close the browser.</h4></center><br> {% endif %} - <a href="{{URL_ROOT}}/exam/" id="home" class="btn btn-success"> Home </a> {% if module_id and not user == "moderator" %} {% if first_unit %} - <a href="{{URL_ROOT}}/exam/next_unit/{{course_id}}/{{module_id}}/{{learning_unit.id}}/1" class="btn btn-info"> Next + <a href="{{URL_ROOT}}/exam/next_unit/{{course_id}}/{{module_id}}/{{learning_unit.id}}/1" class="btn btn-info" id="Next"> Next <span class="glyphicon glyphicon-chevron-right"> </span> </a> {% else %} - <a href="{{URL_ROOT}}/exam/next_unit/{{course_id}}/{{module_id}}/{{learning_unit.id}}" class="btn btn-info"> Next + <a href="{{URL_ROOT}}/exam/next_unit/{{course_id}}/{{module_id}}/{{learning_unit.id}}" class="btn btn-info" id="Next"> Next <span class="glyphicon glyphicon-chevron-right"> </span> </a> {% endif %} + {% else %} + <a href="{{URL_ROOT}}/exam/" id="home" class="btn btn-success"> Home </a> {% endif %} </center> {% endblock content %} diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index a1fd48a..bc96bf5 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -397,6 +397,11 @@ <ul class="list-group"> <a href="{{URL_ROOT}}/exam/manage/courses/edit_lesson/{{lesson.id}}/"> {{ lesson.name }}</a> + {% if lesson.active %} + <span class="label label-success">Active</span> + {% else %} + <span class="label label-danger">Closed</span> + {% endif %} </ul> </td> {% endfor %} <!-- end for lessons --> @@ -431,6 +436,11 @@ <td> <a href="{{URL_ROOT}}/exam/manage/courses/add_module/{{module.id}}/"> {{ module.name }}</a> + {% if module.active %} + <span class="label label-success">Active</span> + {% else %} + <span class="label label-danger">Closed</span> + {% endif %} </td> <td> <a href="{{URL_ROOT}}/exam/manage/courses/designmodule/{{module.id}}"> diff --git a/yaksh/templates/yaksh/design_questionpaper.html b/yaksh/templates/yaksh/design_questionpaper.html index 829e27f..1656e2b 100644 --- a/yaksh/templates/yaksh/design_questionpaper.html +++ b/yaksh/templates/yaksh/design_questionpaper.html @@ -23,8 +23,13 @@ select {% block content %} <input type=hidden id="url_root" value={{ URL_ROOT }}> -<form action="{{ URL_ROOT }}/exam/manage/designquestionpaper/{{ qpaper.quiz.id }}/{{ qpaper.id }}/" method="POST" id="design_q"> -<input class ="btn primary small" type="submit" name="back" id="back" value="Cancel"> +{% if course_id %} + <form action="{{ URL_ROOT }}/exam/manage/designquestionpaper/{{ qpaper.quiz.id }}/{{ qpaper.id }}/{{course_id}}/" method="POST" id="design_q"> + <a href="{{URL_ROOT}}/exam/manage/courses" class="btn btn-danger">Cancel</a> +{% else %} + <form action="{{ URL_ROOT }}/exam/manage/designquestionpaper/{{ qpaper.quiz.id }}/{{ qpaper.id }}/" method="POST" id="design_q"> + <a href="{{URL_ROOT}}/exam/manage/courses/all_quizzes" class="btn btn-danger">Cancel</a> +{% endif %} {% csrf_token %} <input type=hidden name="is_active" id="is_active" value="{{ state }}"> <center><b>Manual mode to design the {{lang}} Question Paper</center><br> diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 2aa55d4..cd4279b 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -100,6 +100,7 @@ def setUpModule(): course.students.add(course_user) course.save() LessonFile.objects.create(lesson=lesson) + CourseStatus.objects.create(course=course, user=course_user) def tearDownModule(): @@ -137,6 +138,13 @@ class LearningModuleTestCases(unittest.TestCase): 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) + + def tearDown(self): + # Remove unit from course status completed units + self.course_status.completed_units.remove(self.learning_unit_one) + self.course_status.completed_units.remove(self.learning_unit_two) def test_learning_module(self): self.assertEqual(self.learning_module.description, 'module one') @@ -197,7 +205,7 @@ class LearningModuleTestCases(unittest.TestCase): # Then self.assertEqual(unit, next_unit) - def test_get_status(self): + def test_get_module_status(self): # Given module_status = 'not attempted' # When @@ -205,6 +213,29 @@ class LearningModuleTestCases(unittest.TestCase): # Then self.assertEqual(status, module_status) + # Module in progress + + # Given + self.course_status.completed_units.add(self.learning_unit_one) + # When + status = self.learning_module.get_status(self.student, self.course) + # Then + self.assertEqual("inprogress", status) + + # Module is completed + + # Given + self.course_status.completed_units.add(self.learning_unit_two) + # When + status = self.learning_module.get_status(self.student, self.course) + # Then + self.assertEqual("completed", status) + + # Module with no units + self.course.learning_module.add(self.learning_module_two) + status = self.learning_module_two.get_status(self.student, self.course) + self.assertEqual("no units", status) + def test_module_completion_percent(self): # for module without learning units percent = self.learning_module_two.get_module_complete_percent( @@ -213,17 +244,12 @@ class LearningModuleTestCases(unittest.TestCase): self.assertEqual(percent, 0) # for module with learning units - lesson = Lesson.objects.get(name='L1') - self.completed_unit = LearningUnit.objects.get(lesson=lesson) - - course_status = CourseStatus.objects.create( - course=self.course, user=self.student) - course_status.completed_units.add(self.completed_unit) - + self.course_status.completed_units.add(self.learning_unit_one) + self.course_status.completed_units.add(self.learning_unit_two) percent = self.learning_module.get_module_complete_percent( self.course, self.student ) - self.assertEqual(percent, 50) + self.assertEqual(percent, 100) class LearningUnitTestCases(unittest.TestCase): diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 9be8d13..3b27338 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -5079,6 +5079,30 @@ class TestLessons(TestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response.context["msg"], err_msg) + # Check if lesson is active + self.lesson.active = False + self.lesson.save() + response = self.client.get( + reverse('yaksh:show_lesson', + kwargs={"lesson_id": self.lesson.id, + "module_id": self.learning_module.id, + "course_id": self.course.id})) + err_msg = "{0} is not active".format(self.lesson.name) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context["msg"], err_msg) + + # Check if module is active + self.learning_module2.active = False + self.learning_module2.save() + 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 = "{0} is not active".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/views.py b/yaksh/views.py index 2bc5dfe..011b417 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -475,6 +475,10 @@ 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 active status + if not learning_module.active: + return view_module(request, module_id, course_id) + # unit module prerequiste check if learning_module.has_prerequisite(): if not learning_module.is_prerequisite_passed(user, course): @@ -1392,7 +1396,8 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None, 'questions': questions, 'fixed_questions': fixed_questions, 'state': state, - 'random_sets': random_sets + 'random_sets': random_sets, + 'course_id': course_id } return my_render_to_response( 'yaksh/design_questionpaper.html', @@ -2348,6 +2353,13 @@ 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 not learn_module.active: + return view_module(request, module_id, course_id) + + if not learn_unit.lesson.active: + 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): msg = "You have not completed the module previous to {0}".format( @@ -2660,6 +2672,10 @@ def view_module(request, module_id, course_id, msg=None): msg = "{0} is either expired or not active".format(course.name) return course_modules(request, course_id, msg) learning_module = course.learning_module.get(id=module_id) + + if not learning_module.active: + msg = "{0} is not active".format(learning_module.name) + 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): |