From 91fa9c6a40e16f43d935db9641b6833605afc1e8 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 17 Oct 2017 12:48:51 +0530 Subject: Add a view to preview and download questionpapers --- yaksh/templates/yaksh/download_questionpaper.html | 38 +++++++++++++++++++++++ yaksh/urls.py | 3 ++ yaksh/views.py | 18 +++++++++++ 3 files changed, 59 insertions(+) create mode 100644 yaksh/templates/yaksh/download_questionpaper.html diff --git a/yaksh/templates/yaksh/download_questionpaper.html b/yaksh/templates/yaksh/download_questionpaper.html new file mode 100644 index 0000000..8b04874 --- /dev/null +++ b/yaksh/templates/yaksh/download_questionpaper.html @@ -0,0 +1,38 @@ +{% extends "base.html" %} + +{% block pagetitle %} Quiz: {{ paper.quiz.description }} {% endblock pagetitle %} + +{% block content %} +
+
+
Maximum Mark(s): {{ paper.total_marks }}
+
Total Time: {{ paper.quiz.duration }}
+
+
+
+
Instructions
+
+ {{ paper.quiz.instructions|safe }} +
+
+{% for question in questions %} +
+
+ {{forloop.counter}}. {{ question.summary }} + Mark(s): {{ question.points }} + +
+
+
Question:
{{ question.description|safe }} + {% if question.type == "mcq" or question.type == "mcc" %} +
Choices:
+ {% for testcase in question.get_test_cases %} +
+ {{ forloop.counter }}. {{ testcase.options|safe }} + {% endfor %} + {% endif %} + +
+
+{% endfor %} +{% endblock %} diff --git a/yaksh/urls.py b/yaksh/urls.py index 08c2091..3120705 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -140,6 +140,7 @@ urlpatterns = [ views.download_assignment_file, name="download_quiz_assignment"), url(r'^manage/courses/download_yaml_template/', views.download_yaml_template, name="download_yaml_template"), +<<<<<<< HEAD url(r'^manage/download_sample_csv/', views.download_sample_csv, name="download_sample_csv"), url(r'^manage/courses/edit_lesson/$', @@ -172,4 +173,6 @@ urlpatterns = [ views.design_course, name="design_course"), url(r'^manage/course_status/(?P\d+)/$', views.course_status, name="course_status"), + url(r'^manage/download_questionpaper/(?P\d+)/$', + views.download_questionpaper, name="download_questionpaper"), ] diff --git a/yaksh/views.py b/yaksh/views.py index 011b417..0dab227 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -9,6 +9,7 @@ from django.core.urlresolvers import reverse from django.contrib.auth import login, logout, authenticate from django.shortcuts import render_to_response, get_object_or_404, redirect from django.template import RequestContext, Context, Template +from django.template.loader import get_template, render_to_string from django.http import Http404 from django.db.models import Sum, Max, Q, F from django.views.decorators.csrf import csrf_exempt @@ -2744,3 +2745,20 @@ def _update_unit_status(course_id, user, unit): # make next available unit as current unit course_status.current_unit = unit course_status.save() + + +@login_required +@email_verified +def download_questionpaper(request, questionpaper_id): + user = request.user + if not is_moderator(user): + raise Http404('You are not allowed to view this page!') + paper = QuestionPaper.objects.get(id=questionpaper_id) + context = { + 'questions': paper._get_questions_for_answerpaper(), + 'paper': paper, + } + + return my_render_to_response( + 'yaksh/download_questionpaper.html', context + ) -- cgit From 7a892b8c664a69bd054efc6c662281e839546b7d Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 7 Nov 2017 15:49:35 +0530 Subject: - Change function names and urls to 'preview_questionpaper' - Add snippet to the questionpaper preview --- yaksh/templates/yaksh/download_questionpaper.html | 38 -------------------- yaksh/templates/yaksh/preview_questionpaper.html | 42 +++++++++++++++++++++++ yaksh/urls.py | 3 ++ yaksh/views.py | 4 +-- 4 files changed, 47 insertions(+), 40 deletions(-) delete mode 100644 yaksh/templates/yaksh/download_questionpaper.html create mode 100644 yaksh/templates/yaksh/preview_questionpaper.html diff --git a/yaksh/templates/yaksh/download_questionpaper.html b/yaksh/templates/yaksh/download_questionpaper.html deleted file mode 100644 index 8b04874..0000000 --- a/yaksh/templates/yaksh/download_questionpaper.html +++ /dev/null @@ -1,38 +0,0 @@ -{% extends "base.html" %} - -{% block pagetitle %} Quiz: {{ paper.quiz.description }} {% endblock pagetitle %} - -{% block content %} -
-
-
Maximum Mark(s): {{ paper.total_marks }}
-
Total Time: {{ paper.quiz.duration }}
-
-
-
-
Instructions
-
- {{ paper.quiz.instructions|safe }} -
-
-{% for question in questions %} -
-
- {{forloop.counter}}. {{ question.summary }} - Mark(s): {{ question.points }} - -
-
-
Question:
{{ question.description|safe }} - {% if question.type == "mcq" or question.type == "mcc" %} -
Choices:
- {% for testcase in question.get_test_cases %} -
- {{ forloop.counter }}. {{ testcase.options|safe }} - {% endfor %} - {% endif %} - -
-
-{% endfor %} -{% endblock %} diff --git a/yaksh/templates/yaksh/preview_questionpaper.html b/yaksh/templates/yaksh/preview_questionpaper.html new file mode 100644 index 0000000..411e4a6 --- /dev/null +++ b/yaksh/templates/yaksh/preview_questionpaper.html @@ -0,0 +1,42 @@ +{% extends "base.html" %} + +{% block pagetitle %} Quiz: {{ paper.quiz.description }} {% endblock pagetitle %} + +{% block content %} +
+
+
Maximum Mark(s): {{ paper.total_marks }}
+
Total Time: {{ paper.quiz.duration }}
+
+
+
+
Instructions
+
+ {{ paper.quiz.instructions|safe }} +
+
+{% for question in questions %} +
+
+ {{forloop.counter}}. {{ question.summary }} + Mark(s): {{ question.points }} + +
+
+
Question:
{{ question.description|safe }} +
Answer:
+ {% if question.type == "code" %} +
{{ question.snippet }}
+ {% endif %} + {% if question.type == "mcq" or question.type == "mcc" %} +
Choices:
+ {% for testcase in question.get_test_cases %} +
+ {{ forloop.counter }}. {{ testcase.options|safe }} + {% endfor %} + {% endif %} + +
+
+{% endfor %} +{% endblock %} diff --git a/yaksh/urls.py b/yaksh/urls.py index 3120705..b4da1c0 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -140,6 +140,7 @@ urlpatterns = [ views.download_assignment_file, name="download_quiz_assignment"), url(r'^manage/courses/download_yaml_template/', views.download_yaml_template, name="download_yaml_template"), +<<<<<<< HEAD <<<<<<< HEAD url(r'^manage/download_sample_csv/', views.download_sample_csv, name="download_sample_csv"), @@ -175,4 +176,6 @@ urlpatterns = [ views.course_status, name="course_status"), url(r'^manage/download_questionpaper/(?P\d+)/$', views.download_questionpaper, name="download_questionpaper"), + url(r'^manage/preview_questionpaper/(?P\d+)/$', + views.preview_questionpaper, name="preview_questionpaper"), ] diff --git a/yaksh/views.py b/yaksh/views.py index 0dab227..94335a2 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -2749,7 +2749,7 @@ def _update_unit_status(course_id, user, unit): @login_required @email_verified -def download_questionpaper(request, questionpaper_id): +def preview_questionpaper(request, questionpaper_id): user = request.user if not is_moderator(user): raise Http404('You are not allowed to view this page!') @@ -2760,5 +2760,5 @@ def download_questionpaper(request, questionpaper_id): } return my_render_to_response( - 'yaksh/download_questionpaper.html', context + 'yaksh/preview_questionpaper.html', context ) -- cgit From 9d689c2478d4f7f6f95f1e647dced17dd93e299c Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 6 Mar 2018 12:01:59 +0530 Subject: Remove conflict related residual comment --- yaksh/urls.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/yaksh/urls.py b/yaksh/urls.py index b4da1c0..f5f8895 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -140,8 +140,6 @@ urlpatterns = [ views.download_assignment_file, name="download_quiz_assignment"), url(r'^manage/courses/download_yaml_template/', views.download_yaml_template, name="download_yaml_template"), -<<<<<<< HEAD -<<<<<<< HEAD url(r'^manage/download_sample_csv/', views.download_sample_csv, name="download_sample_csv"), url(r'^manage/courses/edit_lesson/$', @@ -174,8 +172,6 @@ urlpatterns = [ views.design_course, name="design_course"), url(r'^manage/course_status/(?P\d+)/$', views.course_status, name="course_status"), - url(r'^manage/download_questionpaper/(?P\d+)/$', - views.download_questionpaper, name="download_questionpaper"), url(r'^manage/preview_questionpaper/(?P\d+)/$', views.preview_questionpaper, name="preview_questionpaper"), ] -- cgit From 73d6da4bca9b604a3fe68b8ce843791c948ae285 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 6 Mar 2018 12:05:43 +0530 Subject: Add view button to preview the questionpaper --- yaksh/templates/yaksh/courses.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index bc96bf5..c20f5df 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -358,6 +358,9 @@ {% if quiz.questionpaper_set.get %} Question Paper for {{ quiz.description }} + + View +
{% else %}

No Question Paper -- cgit From 88fbad3f08dfcf8d139f8bc572860469c64e3104 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 6 Mar 2018 20:47:42 +0530 Subject: Multiple fixes: - Add views test cases in test_views.py - Add minutes unit to preview_questionpaper template - Add error handling in views when random user accesses questionpaper --- yaksh/templates/yaksh/preview_questionpaper.html | 2 +- yaksh/test_views.py | 66 ++++++++++++++++++++++++ yaksh/views.py | 4 +- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/yaksh/templates/yaksh/preview_questionpaper.html b/yaksh/templates/yaksh/preview_questionpaper.html index 411e4a6..123218f 100644 --- a/yaksh/templates/yaksh/preview_questionpaper.html +++ b/yaksh/templates/yaksh/preview_questionpaper.html @@ -6,7 +6,7 @@

Maximum Mark(s): {{ paper.total_marks }}
-
Total Time: {{ paper.quiz.duration }}
+
Total Time: {{ paper.quiz.duration }} minutes
diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 3b27338..10cef81 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -4040,6 +4040,24 @@ class TestQuestionPaper(TestCase): timezone='UTC' ) + self.user2_plaintext_pass = 'demo2' + self.user2 = User.objects.create_user( + username='demo_user2', + password=self.user_plaintext_pass, + first_name='first_name2', + last_name='last_name2', + email='demo2@test.com' + ) + + Profile.objects.create( + user=self.user2, + roll_number=11, + institute='IIT', + department='Chemical', + position='Student', + timezone='UTC' + ) + self.teacher_plaintext_pass = 'demo_teacher' self.teacher = User.objects.create_user( username='demo_teacher', @@ -4194,6 +4212,54 @@ class TestQuestionPaper(TestCase): self.learning_module.delete() self.learning_unit.delete() + def test_preview_questionpaper_correct(self): + self.client.login( + username=self.user.username, + password=self.user_plaintext_pass + ) + + # Should successfully preview question paper + response = self.client.get( + reverse('yaksh:preview_questionpaper', + kwargs={"questionpaper_id": self.question_paper.id} + ) + ) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'yaksh/preview_questionpaper.html') + self.assertEqual( + response.context['questions'], + self.questions_list + ) + self.assertEqual(response.context['paper'], self.question_paper) + + def test_preview_questionpaper_without_moderator(self): + self.client.login( + username=self.user2.username, + password=self.user_plaintext_pass + ) + + # Should raise an HTTP 404 response + response = self.client.get( + reverse('yaksh:preview_questionpaper', + kwargs={"questionpaper_id": self.question_paper.id} + ) + ) + self.assertEqual(response.status_code, 404) + + def test_preview_qustionpaper_without_quiz_owner(self): + self.client.login( + username=self.teacher.username, + password=self.teacher_plaintext_pass + ) + + # Should raise an HTTP 404 response + response = self.client.get( + reverse('yaksh:preview_questionpaper', + kwargs={"questionpaper_id": self.question_paper.id} + ) + ) + self.assertEqual(response.status_code, 404) + def test_mcq_attempt_right_after_wrong(self): """ Case:- Check if answerpaper and answer marks are updated after attempting same mcq question with wrong answer and then right diff --git a/yaksh/views.py b/yaksh/views.py index 94335a2..2b3c891 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1883,7 +1883,7 @@ def create_demo_course(request): user = request.user ci = RequestContext(request) if not is_moderator(user): - raise("You are not allowed to view this page") + raise Http404("You are not allowed to view this page") demo_course = Course() success = demo_course.create_demo(user) if success: @@ -2754,6 +2754,8 @@ def preview_questionpaper(request, questionpaper_id): if not is_moderator(user): raise Http404('You are not allowed to view this page!') paper = QuestionPaper.objects.get(id=questionpaper_id) + if not paper.quiz.creator == user: + raise Http404('This questionpaper does not belong to you') context = { 'questions': paper._get_questions_for_answerpaper(), 'paper': paper, -- cgit