diff options
author | adityacp | 2020-03-28 16:59:10 +0530 |
---|---|---|
committer | adityacp | 2020-03-28 16:59:10 +0530 |
commit | b835440b1e2ca0059e95b6848cb87cc5724ee967 (patch) | |
tree | 9442718781c94d7c2be113283b297620f6f91fd2 /yaksh | |
parent | e8573822d3ed25306d5d2faf946633f2c17997b0 (diff) | |
download | online_test-b835440b1e2ca0059e95b6848cb87cc5724ee967.tar.gz online_test-b835440b1e2ca0059e95b6848cb87cc5724ee967.tar.bz2 online_test-b835440b1e2ca0059e95b6848cb87cc5724ee967.zip |
Fix workflow for creating modules, lessons, quizzes
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/templates/yaksh/add_course.html | 18 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_exercise.html | 14 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_lesson.html | 10 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_quiz.html | 14 | ||||
-rw-r--r-- | yaksh/templates/yaksh/course_added_modules.html | 127 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 16 | ||||
-rw-r--r-- | yaksh/templates/yaksh/design_questionpaper.html | 9 | ||||
-rw-r--r-- | yaksh/test_views.py | 213 | ||||
-rw-r--r-- | yaksh/urls.py | 39 | ||||
-rw-r--r-- | yaksh/views.py | 153 |
10 files changed, 252 insertions, 361 deletions
diff --git a/yaksh/templates/yaksh/add_course.html b/yaksh/templates/yaksh/add_course.html index 97c6f56..0072a95 100644 --- a/yaksh/templates/yaksh/add_course.html +++ b/yaksh/templates/yaksh/add_course.html @@ -26,22 +26,10 @@ Add/Edit Course </a> </li> - <li class="nav-item dropdown hide"> - <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="true">More</a> - <div class="dropdown-menu hide" x-placement="bottom-start" style="position: absolute; transform: translate3d(0px, 37px, 0px); top: 0px; left: 0px; will-change: transform;"> - <a class="dropdown-item" href="{% url 'yaksh:show_all_quizzes' %}"> - View Quizzes - </a> - <a class="dropdown-item" href="{% url 'yaksh:show_all_lessons' %}"> - View Lessons - </a> - <a class="dropdown-item" href="{% url 'yaksh:show_all_modules' %}"> - View Modules - </a> - <a href="{% url 'grades:grading_systems'%}" class="dropdown-item" > - View Grading Systems + <li class="nav-item"> + <a href="{% url 'grades:grading_systems'%}" class="nav-link" > + Add/View Grading Systems </a> - </div> </li> </ul> </div> diff --git a/yaksh/templates/yaksh/add_exercise.html b/yaksh/templates/yaksh/add_exercise.html index d3d9068..542d1c4 100644 --- a/yaksh/templates/yaksh/add_exercise.html +++ b/yaksh/templates/yaksh/add_exercise.html @@ -23,17 +23,9 @@ </div> {% endfor %} {% endif %} - {% if course_id %} - <a class="btn btn-primary" href="{% url 'yaksh:get_course_modules' course_id %}"> - <i class="fa fa-arrow-left"></i> - Back - </a> - {% else %} - <a class="btn btn-primary" href="{% url 'yaksh:show_all_quizzes' %}"> - <i class="fa fa-arrow-left"></i> - Back - </a> - {% endif %} + <a class="btn btn-primary" href="{% url 'yaksh:get_course_modules' course_id %}"> + <i class="fa fa-arrow-left"></i> Back + </a> <br><br> <form name=frm id=frm action="" method="post" > {% csrf_token %} diff --git a/yaksh/templates/yaksh/add_lesson.html b/yaksh/templates/yaksh/add_lesson.html index 99fc31a..b984db0 100644 --- a/yaksh/templates/yaksh/add_lesson.html +++ b/yaksh/templates/yaksh/add_lesson.html @@ -26,17 +26,9 @@ <div class="container"> <div class="row justify-content-center form-group"> <div class="col-md-9 col-md-offset-4"> - {% if course_id %} <a class="btn btn-primary" href="{% url 'yaksh:get_course_modules' course_id %}"> - <i class="fa fa-arrow-left"></i> - Back + <i class="fa fa-arrow-left"></i> Back </a> - {% else %} - <a class="btn btn-primary" href="{% url 'yaksh:show_all_lessons' %}"> - <i class="fa fa-arrow-left"></i> - Back - </a> - {% endif %} <br> {% if messages %} <br> diff --git a/yaksh/templates/yaksh/add_quiz.html b/yaksh/templates/yaksh/add_quiz.html index 5497eeb..55e3bd6 100644 --- a/yaksh/templates/yaksh/add_quiz.html +++ b/yaksh/templates/yaksh/add_quiz.html @@ -35,17 +35,9 @@ </div> {% endfor %} {% endif %} - {% if course_id %} - <a class="btn btn-primary" href="{% url 'yaksh:get_course_modules' course_id %}"> - <i class="fa fa-arrow-left"></i> - Back - </a> - {% else %} - <a class="btn btn-primary" href="{% url 'yaksh:show_all_quizzes' %}"> - <i class="fa fa-arrow-left"></i> - Back - </a> - {% endif %} + <a class="btn btn-primary" href="{% url 'yaksh:get_course_modules' course_id %}"> + <i class="fa fa-arrow-left"></i> Back + </a> <br><br> <form name=frm id=frm action="" method="post" > {% csrf_token %} diff --git a/yaksh/templates/yaksh/course_added_modules.html b/yaksh/templates/yaksh/course_added_modules.html index c70eb7a..7ea55e8 100644 --- a/yaksh/templates/yaksh/course_added_modules.html +++ b/yaksh/templates/yaksh/course_added_modules.html @@ -1,46 +1,99 @@ {% if is_modules %} {% block pagetitle %} <center> <h3>Course Modules</h3> </center> {% endblock %} + <a href="{% url 'yaksh:add_module' course.id %}" class="btn btn-primary btn-lg"> + <i class="fa fa-plus-circle"></i> Add Module + </a> + <br><br> {% if modules %} - <table class="table table-responsive"> - <tr> - <th>Module</th> - <th>Module Design</th> - <th>Lessons/Quizzes</th> - </tr> + <center> + <div class="alert alert-dismissible alert-info"> + <strong> + For additional module settings, Click on Design Module + </strong> + </div> + </center> {% for module in modules %} - <tr> - <td> - <a href="{% url 'yaksh:edit_module' module.id course.id %}"> - {{module.name}}</a> - </td> - <td> - <a href="{% url 'yaksh:design_module' module.id course.id %}"> - Add Quizzes/Lessons for {{module.name}} - </a> - </td> - <td> - {% for unit in module.get_learning_units %} - <ul class="inputs-list"> - <li> - {% if unit.type == "quiz" %} - {% if unit.quiz.is_exercise %} - <a href="{% url 'yaksh:edit_exercise' unit.quiz.id course.id %}"> - {{unit.quiz.description}}</a> + <div class="card"> + <div class="card-header"> + {{module.name}} + </div> + <div class="card-body"> + <div class="row"> + <div class="col"> + <a href="{% url 'yaksh:edit_lesson' course.id module.id %}" class="btn btn-info"> + <i class="fa fa-plus-circle"></i> Add Lesson + </a> + </div> + <div class="col"> + <a href="{% url 'yaksh:add_quiz' course.id module.id %}" class="btn btn-success"> + <i class="fa fa-plus-circle"></i> Add Quiz + </a> + </div> + <div class="col"> + <a href="{% url 'yaksh:add_exercise' course.id module.id %}" class="btn btn-dark"> + <i class="fa fa-plus-circle"></i> Add Exercise + </a> + </div> + <div class="col"> + <a href="{% url 'yaksh:design_module' module.id course.id %}" class="btn btn-secondary"> + Design Module + </a> + </div> + </div> + <br> + {% with module.get_learning_units as units %} + {% if units %} + <table class="table table-responsive-sm"> + {% for unit in units %} + <tr> + <td> + {% if unit.type == "quiz" %} + {% if unit.quiz.is_exercise %} + <a href="{% url 'yaksh:edit_exercise' course.id module.id unit.quiz.id %}"> + {{unit.quiz.description}}</a> + {% else %} + <a href="{% url 'yaksh:edit_quiz' course.id module.id unit.quiz.id %}"> + {{unit.quiz.description}}</a> + {% endif %} + {% else %} + <a href="{% url 'yaksh:edit_lesson' course.id module.id unit.lesson.id %}"> + {{unit.lesson.name}}</a> + {% endif %} + </td> + <td> + {% if unit.type == "quiz" %} + {% with unit.quiz as quiz %} + {% if quiz.questionpaper_set.get.id %} + <a href="{% url 'yaksh:designquestionpaper' course.id quiz.id quiz.questionpaper_set.get.id %}" class="btn btn-primary"> + <i class="fa fa-edit"></i> + Edit Question Paper + </a> + {% else %} + <a href="{% url 'yaksh:designquestionpaper' course.id quiz.id %}" class="btn btn-success"> + <i class="fa fa-plus-circle"></i> + Add Question Paper + </a> + {% endif %} + {% endwith %} + {% else %} + ------- + {% endif %} + </td> + </tr> + {% endfor %} + </table> {% else %} - <a href="{% url 'yaksh:edit_quiz' unit.quiz.id course.id %}"> - {{unit.quiz.description}}</a> + <center> + <span class="badge badge-warning"> + <big>No lesson/quiz added</big> + </span> + </center> {% endif %} - {% else %} - <a href="{% url 'yaksh:edit_lesson' unit.lesson.id course.id %}"> - {{unit.lesson.name}}</a> - {% endif %} - </li> - </ul> - {% endfor %} - </td> - </tr> - {% endfor %} <!-- end for modules --> - </table> + {% endwith %} + </div> + </div> + <br> + {% endfor %} {% else %} <center> <span class="badge badge-warning"><big>No learning modules</big></span> diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 084d0f6..bce005f 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -32,22 +32,10 @@ Add/Edit Course </a> </li> - <li class="nav-item dropdown hide"> - <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="true">More</a> - <div class="dropdown-menu hide" x-placement="bottom-start" style="position: absolute; transform: translate3d(0px, 37px, 0px); top: 0px; left: 0px; will-change: transform;"> - <a class="dropdown-item" href="{% url 'yaksh:show_all_quizzes' %}"> - Add/View Quizzes - </a> - <a class="dropdown-item" href="{% url 'yaksh:show_all_lessons' %}"> - Add/View Lessons - </a> - <a class="dropdown-item" href="{% url 'yaksh:show_all_modules' %}"> - Add/View Modules - </a> - <a href="{% url 'grades:grading_systems'%}" class="dropdown-item" > + <li class="nav-item"> + <a href="{% url 'grades:grading_systems'%}" class="nav-link" > Add/View Grading Systems </a> - </div> </li> </ul> </div> diff --git a/yaksh/templates/yaksh/design_questionpaper.html b/yaksh/templates/yaksh/design_questionpaper.html index 6e916a3..ffbdf5f 100644 --- a/yaksh/templates/yaksh/design_questionpaper.html +++ b/yaksh/templates/yaksh/design_questionpaper.html @@ -17,17 +17,10 @@ {% block content %} <div class="container"> <input type=hidden id="url_root" value={{ URL_ROOT }}> -{% if course_id %} - <form action="{% url 'yaksh:designquestionpaper' qpaper.quiz.id qpaper.id course_id %}" method="POST" id="design_q"> + <form action="{% url 'yaksh:designquestionpaper' course_id qpaper.quiz.id qpaper.id %}" method="POST" id="design_q"> <a href="{% url 'yaksh:get_course_modules' course_id %}" class="btn btn-primary"> <i class="fa fa-arrow-left"></i> Back </a> -{% else %} - <form action="{% url 'yaksh:designquestionpaper' qpaper.quiz.id qpaper.id %}" method="POST" id="design_q"> - <a href="{% url 'yaksh:show_all_quizzes' %}" class="btn btn-primary"> - <i class="fa fa-arrow-left"></i> Back - </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_views.py b/yaksh/test_views.py index 569d4d7..6f28add 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -1083,6 +1083,10 @@ class TestAddQuiz(TestCase): enrollment="Enroll Request", creator=self.user ) + self.module = LearningModule.objects.create( + name="My test module", creator=self.user, description="Test" + ) + 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), @@ -1112,10 +1116,17 @@ class TestAddQuiz(TestCase): """ If not logged in redirect to login page """ - response = self.client.get(reverse('yaksh:add_quiz'), - follow=True - ) - redirect_destination = '/exam/login/?next=/exam/manage/addquiz/' + response = self.client.get( + reverse('yaksh:add_quiz', + kwargs={'course_id': self.course.id, + 'module_id': self.module.id}), + follow=True + ) + redirect_destination = ( + '/exam/login/?next=/exam/manage/addquiz/{0}/{1}/'.format( + self.course.id, self.module.id + ) + ) self.assertRedirects(response, redirect_destination) def test_add_quiz_denies_non_moderator(self): @@ -1126,9 +1137,12 @@ class TestAddQuiz(TestCase): username=self.student.username, password=self.student_plaintext_pass ) - response = self.client.get(reverse('yaksh:add_quiz'), - follow=True - ) + response = self.client.get( + reverse('yaksh:add_quiz', + kwargs={'course_id': self.course.id, + 'module_id': self.module.id}), + follow=True + ) self.assertEqual(response.status_code, 404) def test_add_quiz_get(self): @@ -1139,8 +1153,12 @@ class TestAddQuiz(TestCase): username=self.user.username, password=self.user_plaintext_pass ) - response = self.client.get(reverse('yaksh:add_quiz') - ) + response = self.client.get( + reverse('yaksh:add_quiz', + kwargs={'course_id': self.course.id, + 'module_id': self.module.id} + ) + ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'yaksh/add_quiz.html') self.assertIsNotNone(response.context['form']) @@ -1156,7 +1174,9 @@ class TestAddQuiz(TestCase): tzone = pytz.timezone('UTC') response = self.client.post( reverse('yaksh:edit_quiz', - kwargs={'quiz_id': self.quiz.id}), + kwargs={'course_id': self.course.id, + 'module_id': self.module.id, + 'quiz_id': self.quiz.id}), data={ 'start_date_time': '2016-01-10 09:00:15', 'end_date_time': '2016-01-15 09:00:15', @@ -1198,7 +1218,9 @@ class TestAddQuiz(TestCase): tzone = pytz.timezone('UTC') response = self.client.post( - reverse('yaksh:add_quiz'), + reverse('yaksh:add_quiz', + kwargs={'course_id': self.course.id, + 'module_id': self.module.id}), data={ 'start_date_time': '2016-01-10 09:00:15', 'end_date_time': '2016-01-15 09:00:15', @@ -1233,11 +1255,18 @@ class TestAddQuiz(TestCase): """ If not logged in redirect to login page """ - response = self.client.get(reverse('yaksh:add_exercise'), - follow=True - ) - redirect_destination = '/exam/login/?next=/exam/manage/add_exercise/' - self.assertRedirects(response, redirect_destination) + response = self.client.get( + reverse('yaksh:add_exercise', + kwargs={'course_id': self.course.id, + 'module_id': self.module.id}), + follow=True + ) + redirect = ( + '/exam/login/?next=/exam/manage/add_exercise/{0}/{1}/'.format( + self.course.id, self.module.id + ) + ) + self.assertRedirects(response, redirect) def test_add_exercise_denies_non_moderator(self): """ @@ -1247,9 +1276,12 @@ class TestAddQuiz(TestCase): username=self.student.username, password=self.student_plaintext_pass ) - response = self.client.get(reverse('yaksh:add_exercise'), - follow=True - ) + response = self.client.get( + reverse('yaksh:add_exercise', + kwargs={'course_id': self.course.id, + 'module_id': self.module.id}), + follow=True + ) self.assertEqual(response.status_code, 404) def test_add_exercise_get(self): @@ -1260,8 +1292,11 @@ class TestAddQuiz(TestCase): username=self.user.username, password=self.user_plaintext_pass ) - response = self.client.get(reverse('yaksh:add_exercise') - ) + response = self.client.get( + reverse('yaksh:add_exercise', + kwargs={'course_id': self.course.id, + 'module_id': self.module.id}) + ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'yaksh/add_exercise.html') self.assertIsNotNone(response.context['form']) @@ -1276,7 +1311,9 @@ class TestAddQuiz(TestCase): ) response = self.client.post( reverse('yaksh:edit_exercise', - kwargs={'quiz_id': self.exercise.id}), + kwargs={'course_id': self.course.id, + 'module_id': self.module.id, + 'quiz_id': self.exercise.id}), data={ 'description': 'updated demo exercise', 'active': True @@ -1301,7 +1338,9 @@ class TestAddQuiz(TestCase): password=self.user_plaintext_pass ) response = self.client.post( - reverse('yaksh:add_exercise'), + reverse('yaksh:add_exercise', + kwargs={'course_id': self.course.id, + 'module_id': self.module.id}), data={ 'description': "Demo Exercise", 'active': True @@ -1317,19 +1356,6 @@ class TestAddQuiz(TestCase): self.assertEqual(new_exercise.pass_criteria, 0) self.assertTrue(new_exercise.is_exercise) - def test_show_all_quizzes(self): - self.client.login( - username=self.user.username, - password=self.user_plaintext_pass - ) - response = self.client.get( - reverse('yaksh:show_all_quizzes'), - follow=True - ) - self.assertEqual(response.status_code, 200) - self.assertEqual(response.context['quizzes'][0], self.quiz) - self.assertTemplateUsed(response, "yaksh/quizzes.html") - class TestAddAsModerator(TestCase): def setUp(self): @@ -2344,51 +2370,6 @@ class TestSearchFilters(TestCase): self.assertIsNotNone(response.context['form']) self.assertIn(self.user1_course1, response.context['courses']) - def test_quizzes_search_filter(self): - """ Test to check if quizzes are obtained with tags and status """ - self.client.login( - username=self.user1.username, - password=self.user1_plaintext_pass - ) - response = self.client.post( - reverse('yaksh:show_all_quizzes'), - data={'quiz_tags': 'demo', 'quiz_status': 'active'} - ) - self.assertEqual(response.status_code, 200) - self.assertTemplateUsed(response, 'yaksh/quizzes.html') - self.assertIsNotNone(response.context['form']) - self.assertIn(self.quiz1, response.context['quizzes']) - - def test_lessons_search_filter(self): - """ Test to check if lessons are obtained with tags and status """ - self.client.login( - username=self.user1.username, - password=self.user1_plaintext_pass - ) - response = self.client.post( - reverse('yaksh:show_all_lessons'), - data={'lesson_tags': 'demo', 'lesson_status': 'active'} - ) - self.assertEqual(response.status_code, 200) - self.assertTemplateUsed(response, 'yaksh/lessons.html') - self.assertIsNotNone(response.context['form']) - self.assertIn(self.lesson1, response.context['lessons']) - - def test_learning_modules_search_filter(self): - """ Test to check if learning modules are obtained with tags and status """ - self.client.login( - username=self.user1.username, - password=self.user1_plaintext_pass - ) - response = self.client.post( - reverse('yaksh:show_all_modules'), - data={'module_tags': 'demo', 'module_status': 'active'} - ) - self.assertEqual(response.status_code, 200) - self.assertTemplateUsed(response, 'yaksh/modules.html') - self.assertIsNotNone(response.context['form']) - self.assertIn(self.learning_module1, response.context['modules']) - class TestAddCourse(TestCase): def setUp(self): @@ -5491,14 +5472,17 @@ class TestQuestionPaper(TestCase): response = self.client.get( reverse('yaksh:designquestionpaper', - kwargs={"quiz_id": self.demo_quiz.id, - "questionpaper_id": self.question_paper.id})) + kwargs={ + "course_id": self.course.id, + "quiz_id": self.demo_quiz.id, + "questionpaper_id": self.question_paper.id})) self.assertEqual(response.status_code, 404) # Design question paper for a quiz response = self.client.post( reverse('yaksh:designquestionpaper', - kwargs={"quiz_id": self.quiz_without_qp.id}), + kwargs={"course_id": self.course.id, + "quiz_id": self.quiz_without_qp.id}), data={"marks": "1.0", "question_type": "code"}) self.assertEqual(response.status_code, 200) self.assertIsNotNone(response.context['questions']) @@ -5511,7 +5495,8 @@ class TestQuestionPaper(TestCase): response = self.client.get( reverse('yaksh:designquestionpaper', - kwargs={"quiz_id": self.demo_quiz.id, + kwargs={"course_id": self.course.id, + "quiz_id": self.demo_quiz.id, "questionpaper_id": self.question_paper.id})) self.assertEqual(response.status_code, 404) @@ -5523,7 +5508,8 @@ class TestQuestionPaper(TestCase): # Should not allow teacher to view question paper response = self.client.get( reverse('yaksh:designquestionpaper', - kwargs={"quiz_id": self.quiz.id, + kwargs={"course_id": self.course.id, + "quiz_id": self.quiz.id, "questionpaper_id": self.question_paper.id})) self.assertEqual(response.status_code, 404) @@ -5792,14 +5778,14 @@ class TestLearningModule(TestCase): ) # Student tries to add learning module - response = self.client.post(reverse('yaksh:add_module'), - data={"name": "test module1", - "description": "my test1", - "Save": "Save"}) + response = self.client.post( + reverse('yaksh:add_module', kwargs={"course_id": self.course.id}), + data={"name": "test module1", + "description": "my test1", + "Save": "Save"}) self.assertEqual(response.status_code, 404) # Student tries to view learning modules - response = self.client.get(reverse('yaksh:show_all_modules')) self.assertEqual(response.status_code, 404) def test_add_new_module(self): @@ -5810,10 +5796,11 @@ class TestLearningModule(TestCase): ) # Test add new module - response = self.client.post(reverse('yaksh:add_module'), - data={"name": "test module1", - "description": "my test1", - "Save": "Save"}) + response = self.client.post( + reverse('yaksh:add_module', kwargs={"course_id": self.course.id}), + data={"name": "test module1", + "description": "my test1", + "Save": "Save"}) self.assertEqual(response.status_code, 200) learning_module = LearningModule.objects.get(name="test module1") @@ -5833,7 +5820,8 @@ class TestLearningModule(TestCase): # Test add new module response = self.client.post( reverse('yaksh:edit_module', - kwargs={"module_id": self.learning_module.id}), + kwargs={"course_id": self.course.id, + "module_id": self.learning_module.id}), data={"name": "test module2", "description": "my test2", "Save": "Save"}) @@ -5846,17 +5834,6 @@ class TestLearningModule(TestCase): self.assertEqual(learning_module.html_data, Markdown().convert("my test2")) - def test_show_all_modules(self): - """Try to get all learning modules""" - self.client.login( - username=self.user.username, - password=self.user_plaintext_pass - ) - response = self.client.get(reverse('yaksh:show_all_modules')) - self.assertEqual(response.status_code, 200) - self.assertEqual(response.context['modules'][0], - self.learning_module) - def test_teacher_can_edit_module(self): """ Check if teacher can edit the module """ self.client.login( @@ -6178,7 +6155,8 @@ class TestLessons(TestCase): response = self.client.get( reverse('yaksh:edit_lesson', kwargs={"lesson_id": self.lesson.id, - "course_id": self.course.id})) + "course_id": self.course.id, + "module_id": self.learning_module.id})) self.assertEqual(response.status_code, 404) def test_teacher_can_edit_lesson(self): @@ -6192,7 +6170,8 @@ class TestLessons(TestCase): response = self.client.post( reverse('yaksh:edit_lesson', kwargs={"lesson_id": self.lesson.id, - "course_id": self.course.id}), + "course_id": self.course.id, + "module_id": self.learning_module.id}), data={"name": "updated lesson", "description": "updated description", "Lesson_files": dummy_file, @@ -6201,7 +6180,7 @@ class TestLessons(TestCase): ) # Teacher edits existing lesson and adds file - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 302) updated_lesson = Lesson.objects.get(name="updated lesson") self.assertEqual(updated_lesson.description, "updated description") self.assertEqual(updated_lesson.creator, self.user) @@ -6216,7 +6195,8 @@ class TestLessons(TestCase): response = self.client.post( reverse('yaksh:edit_lesson', kwargs={"lesson_id": self.lesson.id, - "course_id": self.course.id}), + "course_id": self.course.id, + "module_id": self.learning_module.id}), data={"delete_files": [str(lesson_files.id)], "Delete": "Delete"} ) @@ -6287,17 +6267,6 @@ class TestLessons(TestCase): 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( - username=self.user.username, - password=self.user_plaintext_pass - ) - response = self.client.get(reverse('yaksh:show_all_lessons')) - self.assertEqual(response.status_code, 200) - self.assertTemplateUsed(response, "yaksh/lessons.html") - self.assertEqual(response.context["lessons"][0], self.lesson) - def test_preview_lesson_description(self): """ Test preview lesson description converted from md to html""" self.client.login( diff --git a/yaksh/urls.py b/yaksh/urls.py index b53d335..bdc3330 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -63,15 +63,13 @@ urlpatterns = [ url(r'^manage/addquestion/$', views.add_question, name="add_question"), url(r'^manage/addquestion/(?P<question_id>\d+)/$', views.add_question, name="add_question"), - url(r'^manage/addquiz/$', views.add_quiz, name='add_quiz'), - url(r'^manage/add_exercise/$', views.add_exercise, name='add_exercise'), - url(r'^manage/add_exercise/(?P<quiz_id>\d+)/$', views.add_exercise, - name='edit_exercise'), - url(r'^manage/add_exercise/(?P<quiz_id>\d+)/(?P<course_id>\d+)/$', + url(r'^manage/add_exercise/(?P<course_id>\d+)/(?P<module_id>\d+)/$', + views.add_exercise, name='add_exercise'), + url(r'^manage/add_exercise/(?P<course_id>\d+)/(?P<module_id>\d+)/(?P<quiz_id>\d+)$', views.add_exercise, name='edit_exercise'), - url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', - views.add_quiz, name='edit_quiz'), - url(r'^manage/addquiz/(?P<quiz_id>\d+)/(?P<course_id>\d+)$', + url(r'^manage/addquiz/(?P<course_id>\d+)/(?P<module_id>\d+)/$', + views.add_quiz, name='add_quiz'), + url(r'^manage/addquiz/(?P<course_id>\d+)/(?P<module_id>\d+)/(?P<quiz_id>\d+)$', views.add_quiz, name='edit_quiz'), url(r'^manage/gradeuser/$', views.grade_user, name="grade_user"), url(r'^manage/gradeuser/(?P<quiz_id>\d+)/(?P<course_id>\d+)/$', @@ -91,13 +89,10 @@ urlpatterns = [ '(?P<course_id>\d+)/$', views.user_data, name="user_data"), url(r'^manage/user_data/(?P<user_id>\d+)/$', views.user_data), - url(r'^manage/quiz/designquestionpaper/(?P<quiz_id>\d+)/$', - views.design_questionpaper, name='designquestionpaper'), - url(r'^manage/designquestionpaper/(?P<quiz_id>\d+)/' + url(r'^manage/designquestionpaper/(?P<course_id>\d+)/(?P<quiz_id>\d+)/' '(?P<questionpaper_id>\d+)/$', views.design_questionpaper, name='designquestionpaper'), - url(r'^manage/designquestionpaper/(?P<quiz_id>\d+)/' - '(?P<questionpaper_id>\d+)/(?P<course_id>\d+)/$', + url(r'^manage/designquestionpaper/(?P<course_id>\d+)/(?P<quiz_id>\d+)/$', views.design_questionpaper, name='designquestionpaper'), url(r'^manage/statistics/question/(?P<questionpaper_id>\d+)/' '(?P<course_id>\d+)/$', @@ -176,29 +171,19 @@ urlpatterns = [ views.download_yaml_template, name="download_yaml_template"), url(r'^manage/download_sample_csv/', views.download_sample_csv, name="download_sample_csv"), - url(r'^manage/courses/edit_lesson/$', + url(r'^manage/courses/edit_lesson/(?P<course_id>\d+)/(?P<module_id>\d+)/$', views.edit_lesson, name="edit_lesson"), - url(r'^manage/courses/edit_lesson/(?P<lesson_id>\d+)/$', - views.edit_lesson, name="edit_lesson"), - url(r'^manage/courses/edit_lesson/(?P<lesson_id>\d+)/(?P<course_id>\d+)/$', + url(r'^manage/courses/edit_lesson/(?P<course_id>\d+)/(?P<module_id>\d+)/(?P<lesson_id>\d+)/$', views.edit_lesson, name="edit_lesson"), url(r'^manage/courses/designmodule/(?P<module_id>\d+)/$', views.design_module, name="design_module"), url(r'^manage/courses/designmodule/(?P<module_id>\d+)/' '(?P<course_id>\d+)/$', views.design_module, name="design_module"), - url(r'^manage/courses/all_quizzes/$', - views.show_all_quizzes, name="show_all_quizzes"), - url(r'^manage/courses/all_lessons/$', - views.show_all_lessons, name="show_all_lessons"), url(r'^manage/courses/lesson/preview/$', views.preview_html_text, name="preview_html_text"), - url(r'^manage/courses/all_learning_module/$', - views.show_all_modules, name="show_all_modules"), - url(r'^manage/courses/add_module/$', + url(r'^manage/courses/add_module/(?P<course_id>\d+)/$', views.add_module, name="add_module"), - url(r'^manage/courses/add_module/(?P<module_id>\d+)/$', - views.add_module, name="edit_module"), - url(r'^manage/courses/add_module/(?P<module_id>\d+)/(?P<course_id>\d+)/$', + url(r'^manage/courses/add_module/(?P<course_id>\d+)/(?P<module_id>\d+)/$', views.add_module, name="edit_module"), url(r'^manage/courses/designcourse/(?P<course_id>\d+)/$', views.design_course, name="design_course"), diff --git a/yaksh/views.py b/yaksh/views.py index b54461f..e5f9bc2 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -319,7 +319,7 @@ def add_question(request, question_id=None): @login_required @email_verified -def add_quiz(request, quiz_id=None, course_id=None): +def add_quiz(request, course_id=None, module_id=None, quiz_id=None): """To add a new quiz in the database. Create a new quiz and store it.""" user = request.user @@ -331,6 +331,8 @@ def add_quiz(request, quiz_id=None, course_id=None): raise Http404('This quiz does not belong to you') else: quiz = None + if module_id: + module = get_object_or_404(LearningModule, id=module_id) if course_id: course = get_object_or_404(Course, pk=course_id) if not course.is_creator(user) and not course.is_teacher(user): @@ -342,8 +344,16 @@ def add_quiz(request, quiz_id=None, course_id=None): if form.is_valid(): if quiz is None: form.instance.creator = user - form.save() + added_quiz = form.save() + unit, created = LearningUnit.objects.get_or_create( + type="quiz", quiz=added_quiz, order=1 + ) + module.learning_unit.add(unit.id) messages.success(request, "Quiz saved successfully") + return redirect( + reverse("yaksh:edit_quiz", + args=[course_id, module_id, added_quiz.id]) + ) else: form = QuizForm(instance=quiz) context["course_id"] = course_id @@ -354,7 +364,7 @@ def add_quiz(request, quiz_id=None, course_id=None): @login_required @email_verified -def add_exercise(request, quiz_id=None, course_id=None): +def add_exercise(request, course_id=None, module_id=None, quiz_id=None): user = request.user if not is_moderator(user): raise Http404('You are not allowed to view this course !') @@ -364,6 +374,8 @@ def add_exercise(request, quiz_id=None, course_id=None): raise Http404('This quiz does not belong to you') else: quiz = None + if module_id: + module = get_object_or_404(LearningModule, id=module_id) if course_id: course = get_object_or_404(Course, pk=course_id) if not course.is_creator(user) and not course.is_teacher(user): @@ -384,9 +396,17 @@ def add_exercise(request, quiz_id=None, course_id=None): quiz.duration = 1000 quiz.pass_criteria = 0 quiz.save() + unit, created = LearningUnit.objects.get_or_create( + type="quiz", quiz=quiz, order=1 + ) + module.learning_unit.add(unit.id) messages.success( request, "{0} saved successfully".format(quiz.description) ) + return redirect( + reverse("yaksh:edit_exercise", + args=[course_id, module_id, quiz.id]) + ) else: form = ExerciseForm(instance=quiz) context["exercise"] = quiz @@ -1365,8 +1385,7 @@ def _get_questions_from_tags(question_tags, user, active=True): @login_required @email_verified -def design_questionpaper(request, quiz_id, questionpaper_id=None, - course_id=None): +def design_questionpaper(request, course_id, quiz_id, questionpaper_id=None): user = request.user que_tags = Question.objects.filter( active=True, user=user).values_list('tags', flat=True).distinct() @@ -2444,7 +2463,7 @@ def download_yaml_template(request): @login_required @email_verified -def edit_lesson(request, lesson_id=None, course_id=None): +def edit_lesson(request, course_id=None, module_id=None, lesson_id=None): user = request.user if not is_moderator(user): raise Http404('You are not allowed to view this page!') @@ -2454,6 +2473,8 @@ def edit_lesson(request, lesson_id=None, course_id=None): raise Http404('This Lesson does not belong to you') else: lesson = None + if module_id: + module = get_object_or_404(LearningModule, id=module_id) if course_id: course = get_object_or_404(Course, id=course_id) if not course.is_creator(user) and not course.is_teacher(user): @@ -2485,9 +2506,17 @@ def edit_lesson(request, lesson_id=None, course_id=None): LessonFile.objects.get_or_create( lesson=lesson, file=les_file ) + unit, created = LearningUnit.objects.get_or_create( + type="lesson", lesson=lesson, order=1 + ) + module.learning_unit.add(unit.id) messages.success( request, "Saved {0} successfully".format(lesson.name) ) + return redirect( + reverse("yaksh:edit_lesson", + args=[course_id, module_id, lesson.id]) + ) else: context['lesson_form'] = lesson_form context['error'] = lesson_form["video_file"].errors @@ -2591,14 +2620,14 @@ def design_module(request, module_id, course_id=None): for order, value in enumerate(add_values, start_val): learning_id, type = value.split(":") if type == "quiz": - learning_unit = LearningUnit.objects.create( + unit, status = LearningUnit.objects.get_or_create( order=order, quiz_id=learning_id, type=type) else: - learning_unit = LearningUnit.objects.create( + unit = LearningUnit.objects.get_or_create( order=order, lesson_id=learning_id, type=type) - to_add_list.append(learning_unit) + to_add_list.append(unit) learning_module.learning_unit.add(*to_add_list) messages.success(request, "Lesson/Quiz added successfully") else: @@ -2666,7 +2695,7 @@ def design_module(request, module_id, course_id=None): @login_required @email_verified -def add_module(request, module_id=None, course_id=None): +def add_module(request, course_id=None, module_id=None): user = request.user if not is_moderator(user): raise Http404('You are not allowed to view this page!') @@ -2692,6 +2721,7 @@ def add_module(request, module_id=None, course_id=None): module = module_form.save() module.html_data = get_html_text(module.description) module.save() + course.learning_module.add(module.id) messages.success( request, "Saved {0} successfully".format(module.name) @@ -2708,99 +2738,6 @@ def add_module(request, module_id=None, course_id=None): @login_required @email_verified -def show_all_quizzes(request): - user = request.user - if not is_moderator(user): - raise Http404('You are not allowed to view this page!') - quizzes = Quiz.objects.filter(creator=user, is_trial=False) - - form = SearchFilterForm() - - if request.method == 'POST': - quiz_tags = request.POST.get('search_tags') - quiz_status = request.POST.get('search_status') - - if quiz_status == 'select' : - quizzes = quizzes.filter( - description__contains=quiz_tags) - elif quiz_status == 'active' : - quizzes = quizzes.filter( - description__contains=quiz_tags, active=True) - elif quiz_status == 'closed': - quizzes = quizzes.filter( - description__contains=quiz_tags, active=False) - quizzes_found = quizzes.count() - - context = {"quizzes": quizzes, "form": form, - "quizzes_found": quizzes_found} - return my_render_to_response(request, 'yaksh/quizzes.html', context) - - -@login_required -@email_verified -def show_all_lessons(request): - user = request.user - if not is_moderator(user): - raise Http404('You are not allowed to view this page!') - lessons = Lesson.objects.filter(creator=user) - - form = SearchFilterForm() - - if request.method == 'POST': - lesson_tags = request.POST.get('search_tags') - lesson_status = request.POST.get('search_status') - - if lesson_status == 'select' : - lessons = lessons.filter( - description__contains=lesson_tags) - elif lesson_status == 'active' : - lessons = lessons.filter( - description__contains=lesson_tags, active=True) - elif lesson_status == 'closed': - lessons = lessons.filter( - description__contains=lesson_tags, active=False) - lessons_found = lessons.count() - - context = {"lessons": lessons, "form": form, - "lessons_found": lessons_found} - return my_render_to_response(request, 'yaksh/lessons.html', context) - - -@login_required -@email_verified -def show_all_modules(request): - user = request.user - if not is_moderator(user): - raise Http404('You are not allowed to view this page!') - learning_modules = LearningModule.objects.filter( - creator=user, is_trial=False) - - form = SearchFilterForm() - - if request.method == 'POST': - module_tags = request.POST.get('search_tags') - module_status = request.POST.get('search_status') - - if module_status == 'select' : - learning_modules = learning_modules.filter( - name__contains=module_tags) - elif module_status == 'active' : - learning_modules = learning_modules.filter( - name__contains=module_tags, active=True) - elif module_status == 'closed': - learning_modules = learning_modules.filter( - name__contains=module_tags, active=False) - learning_modules_found = learning_modules.count() - - context = {"modules": learning_modules, "form": form, - "modules_found": learning_modules_found} - return my_render_to_response( - request, 'yaksh/modules.html', context - ) - - -@login_required -@email_verified def preview_html_text(request): user = request.user if not is_moderator(user): @@ -2885,10 +2822,12 @@ def design_course(request, course_id): else: start_val = 1 for order, value in enumerate(add_values, start_val): - learning_module = LearningModule.objects.get(id=int(value)) - learning_module.order = order - learning_module.save() - to_add_list.append(learning_module) + module, created = LearningModule.objects.get_or_create( + id=int(value) + ) + module.order = order + module.save() + to_add_list.append(module) course.learning_module.add(*to_add_list) messages.success(request, "Modules added successfully") else: |