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/views.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'yaksh/views.py') 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/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/views.py') 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 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/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'yaksh/views.py') 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