summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authorprathamesh2016-03-16 12:05:27 +0530
committerprathamesh2016-03-16 15:05:29 +0530
commitaab320d8867a15569ddd0da029f13ea5740f6518 (patch)
tree2f0f84db2fd437124c6dce970cd7dd8140d79e3a /yaksh/views.py
parentef3cd39ebdf9d9fc9011ba4bc470ec5018bb8077 (diff)
downloadonline_test-aab320d8867a15569ddd0da029f13ea5740f6518.tar.gz
online_test-aab320d8867a15569ddd0da029f13ea5740f6518.tar.bz2
online_test-aab320d8867a15569ddd0da029f13ea5740f6518.zip
A moderator can download csv file for a given question paper.
csv includes the latest attempt for the quiz/questionpaper. It contains user details and marks for the quiz.
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 9cd6fdb..bdb86b9 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -5,6 +5,7 @@ import stat
from os.path import dirname, pardir, abspath, join, exists
import datetime
import collections
+import csv
from django.http import HttpResponse
from django.contrib.auth import login, logout, authenticate
from django.shortcuts import render_to_response, get_object_or_404, redirect
@@ -1552,6 +1553,50 @@ def user_data(request, username, questionpaper_id=None):
@login_required
+def download_csv(request, questionpaper_id):
+ user = request.user
+ if not is_moderator(user):
+ raise Http404('You are not allowed to view this page!')
+ quiz = Quiz.objects.get(questionpaper=questionpaper_id)
+ if quiz.course.creator != user:
+ raise Http404('The question paper does not belong to your course')
+ papers = AnswerPaper.objects.get_latest_attempts(questionpaper_id)
+ if not papers:
+ return monitor(request, questionpaper_id)
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment; filename="{0}.csv"'.format(
+ (quiz.description).replace('.', ''))
+ writer = csv.writer(response)
+ header = [
+ 'name',
+ 'username',
+ 'roll_number',
+ 'institute',
+ 'marks_obtained',
+ 'total_marks',
+ 'percentage',
+ 'questions',
+ 'questions_answererd',
+ 'status'
+ ]
+ writer.writerow(header)
+ for paper in papers:
+ row = [
+ '{0} {1}'.format(paper.user.first_name, paper.user.last_name),
+ paper.user.username,
+ paper.user.profile.roll_number,
+ paper.user.profile.institute,
+ paper.marks_obtained,
+ paper.question_paper.total_marks,
+ paper.percent,
+ paper.questions, paper.questions_answered,
+ paper.status
+ ]
+ writer.writerow(row)
+ return response
+
+
+@login_required
def grade_user(request, username, questionpaper_id=None):
"""Present an interface with which we can easily grade a user's papers
and update all their marks and also give comments for each paper.