diff options
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index 986038d..03f4f61 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 @@ -1565,6 +1566,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. |