diff options
author | adityacp | 2018-01-15 16:30:26 +0530 |
---|---|---|
committer | adityacp | 2018-01-16 15:20:55 +0530 |
commit | 8006ffb4a5bd54aa960b24f1508d95844fa579de (patch) | |
tree | 5e03c42d8ec18d708b5e17c289310822c5581d51 /yaksh | |
parent | 3abbc557c57eaf2f3d08222034f9a720a1e7a1ed (diff) | |
download | online_test-8006ffb4a5bd54aa960b24f1508d95844fa579de.tar.gz online_test-8006ffb4a5bd54aa960b24f1508d95844fa579de.tar.bz2 online_test-8006ffb4a5bd54aa960b24f1508d95844fa579de.zip |
Change in template, test_views, urls and views
- Allow teacher to edit questionpaper for a quiz
- Add test to check if teacher is allowed to edit questionpaper for a quiz
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/templates/yaksh/add_quiz.html | 1 | ||||
-rw-r--r-- | yaksh/test_views.py | 92 | ||||
-rw-r--r-- | yaksh/urls.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 19 |
4 files changed, 94 insertions, 20 deletions
diff --git a/yaksh/templates/yaksh/add_quiz.html b/yaksh/templates/yaksh/add_quiz.html index d3705e3..bfd8aa1 100644 --- a/yaksh/templates/yaksh/add_quiz.html +++ b/yaksh/templates/yaksh/add_quiz.html @@ -38,6 +38,7 @@ {% if quiz_id and course_id %} <center> <h4>You can check the quiz by attempting it in the following modes:</h4> + <a href="{{URL_ROOT}}/exam/manage/designquestionpaper/{{ quiz_id }}/{{quiz.questionpaper_set.get.id}}/{{course_id}}" class="btn btn-primary">View Question Paper</a> <button class="btn" type="button" name="button" onClick='usermode("{{URL_ROOT}}/exam/manage/usermode/{{quiz_id}}/{{course_id}}/");'>User Mode</button> <button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/godmode/{{quiz_id}}/{{course_id}}/");'> diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 71d6f80..6444465 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -3960,13 +3960,35 @@ class TestQuestionPaper(TestCase): timezone='UTC' ) + self.teacher_plaintext_pass = 'demo_teacher' + self.teacher = User.objects.create_user( + username='demo_teacher', + password=self.teacher_plaintext_pass, + first_name='first_name', + last_name='last_name', + email='demo@test.com' + ) + + Profile.objects.create( + user=self.teacher, + roll_number=10, + institute='IIT', + department='Chemical', + position='Moderator', + timezone='UTC' + ) + # Add to moderator group self.mod_group.user_set.add(self.user) + self.mod_group.user_set.add(self.teacher) self.course = Course.objects.create( name="Python Course", enrollment="Open Enrollment", creator=self.user) + # Add teacher to the course + self.course.teachers.add(self.teacher) + 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), @@ -3976,6 +3998,15 @@ class TestQuestionPaper(TestCase): creator=self.user ) + self.demo_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 2', pass_criteria=40, + creator=self.user + ) + self.learning_unit = LearningUnit.objects.create( order=1, type="quiz", quiz=self.quiz) self.learning_module = LearningModule.objects.create( @@ -3997,8 +4028,6 @@ class TestQuestionPaper(TestCase): ) self.mcq_based_testcase.save() - ordered_questions = str(self.question_mcq.id) - # Mcc Question self.question_mcc = Question.objects.create( summary="Test_mcc_question", description="Test MCC", @@ -4012,8 +4041,6 @@ class TestQuestionPaper(TestCase): ) self.mcc_based_testcase.save() - ordered_questions = ordered_questions + str(self.question_mcc.id) - # Integer Question self.question_int = Question.objects.create( summary="Test_mcc_question", description="Test MCC", @@ -4026,8 +4053,6 @@ class TestQuestionPaper(TestCase): ) self.int_based_testcase.save() - ordered_questions = ordered_questions + str(self.question_int.id) - # String Question self.question_str = Question.objects.create( summary="Test_mcc_question", description="Test MCC", @@ -4054,17 +4079,19 @@ class TestQuestionPaper(TestCase): ) self.float_based_testcase.save() - ordered_questions = ordered_questions + str(self.question_float.id) - - questions_list = [self.question_mcq, self.question_mcc, - self.question_int, self.question_str, - self.question_float] - + self.questions_list = [self.question_mcq, self.question_mcc, + self.question_int, self.question_str, + self.question_float] + questions_order = ",".join([ + str(self.question_mcq.id), str(self.question_mcc.id), + str(self.question_int.id), str(self.question_str.id), + str(self.question_float.id) + ]) self.question_paper = QuestionPaper.objects.create( quiz=self.quiz, - total_marks=5.0, fixed_question_order=ordered_questions + total_marks=5.0, fixed_question_order=questions_order ) - self.question_paper.fixed_questions.add(*questions_list) + self.question_paper.fixed_questions.add(*self.questions_list) self.answerpaper = AnswerPaper.objects.create( user=self.user, question_paper=self.question_paper, attempt_number=1, @@ -4073,12 +4100,14 @@ class TestQuestionPaper(TestCase): user_ip="127.0.0.1", status="inprogress", passed=False, percent=0, marks_obtained=0, course=self.course ) - self.answerpaper.questions.add(*questions_list) + self.answerpaper.questions.add(*self.questions_list) def tearDown(self): self.client.logout() self.user.delete() + self.teacher.delete() self.quiz.delete() + self.demo_quiz.delete() self.course.delete() self.answerpaper.delete() self.question_mcq.delete() @@ -4352,6 +4381,39 @@ class TestQuestionPaper(TestCase): wrong_answer_paper = AnswerPaper.objects.get(id=self.answerpaper.id) self.assertEqual(wrong_answer_paper.marks_obtained, 0) + def test_design_questionpaper(self): + """ Test design Question Paper """ + + # Should fail if Question paper is not the one which is associated + # with a quiz + self.client.login( + username=self.user.username, + password=self.user_plaintext_pass + ) + + response = self.client.get( + reverse('yaksh:designquestionpaper', + kwargs={"quiz_id": self.demo_quiz.id, + "questionpaper_id": self.question_paper.id})) + self.assertEqual(response.status_code, 404) + + # Should allow course teacher to edit question paper + self.client.login( + username=self.teacher.username, + password=self.teacher_plaintext_pass + ) + + response = self.client.get( + reverse('yaksh:designquestionpaper', + kwargs={"quiz_id": self.quiz.id, + "course_id": self.course.id, + "questionpaper_id": self.question_paper.id})) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'yaksh/design_questionpaper.html') + self.assertEqual(response.context['fixed_questions'], + self.questions_list) + self.assertEqual(response.context['qpaper'], self.question_paper) + class TestLearningModule(TestCase): def setUp(self): diff --git a/yaksh/urls.py b/yaksh/urls.py index b4bbb41..ecbd0d3 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -76,6 +76,8 @@ urlpatterns = [ name='design_questionpaper'), url(r'^manage/designquestionpaper/(?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+)/$', + views.design_questionpaper, name='designquestionpaper'), url(r'^manage/statistics/question/(?P<questionpaper_id>\d+)/(?P<course_id>\d+)/$', views.show_statistics, name="show_statistics"), url(r'^manage/statistics/question/(?P<questionpaper_id>\d+)/(?P<attempt_number>\d+)/(?P<course_id>\d+)/$', diff --git a/yaksh/views.py b/yaksh/views.py index 49249ca..21c79f3 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -324,6 +324,7 @@ def add_quiz(request, quiz_id=None, course_id=None): form = QuizForm(instance=quiz) context["quiz_id"] = quiz_id context["course_id"] = course_id + context["quiz"] = quiz context["form"] = form return my_render_to_response( 'yaksh/add_quiz.html', context, context_instance=ci @@ -1291,14 +1292,21 @@ def _remove_already_present(questionpaper_id, questions): @login_required @email_verified -def design_questionpaper(request, quiz_id, questionpaper_id=None): +def design_questionpaper(request, quiz_id, questionpaper_id=None, + course_id=None): user = request.user if not is_moderator(user): raise Http404('You are not allowed to view this page!') - quiz = Quiz.objects.get(id=quiz_id) - if not quiz.creator == user: - raise Http404('This course does not belong to you') + if quiz_id: + quiz = get_object_or_404(Quiz, pk=quiz_id) + if quiz.creator != user and not course_id: + raise Http404('This quiz does not belong to you') + if course_id: + course = get_object_or_404(Course, pk=course_id) + if not course.is_creator(user) and not course.is_teacher(user): + raise Http404('This quiz does not belong to you') + filter_form = QuestionFilterForm(user=user) questions = None marks = None @@ -1306,7 +1314,8 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None): if questionpaper_id is None: question_paper = QuestionPaper.objects.get_or_create(quiz_id=quiz_id)[0] else: - question_paper = get_object_or_404(QuestionPaper, id=questionpaper_id) + question_paper = get_object_or_404(QuestionPaper, id=questionpaper_id, + quiz_id=quiz_id) qpaper_form = QuestionPaperForm(instance=question_paper) if request.method == 'POST': |