summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authorPrabhu Ramachandran2016-03-17 16:50:04 +0530
committerPrabhu Ramachandran2016-03-17 16:50:04 +0530
commit424e6c94237a1d9b5a24ed6c2a49a433034304ca (patch)
tree2f0f84db2fd437124c6dce970cd7dd8140d79e3a /yaksh
parentef3cd39ebdf9d9fc9011ba4bc470ec5018bb8077 (diff)
parentaab320d8867a15569ddd0da029f13ea5740f6518 (diff)
downloadonline_test-424e6c94237a1d9b5a24ed6c2a49a433034304ca.tar.gz
online_test-424e6c94237a1d9b5a24ed6c2a49a433034304ca.tar.bz2
online_test-424e6c94237a1d9b5a24ed6c2a49a433034304ca.zip
Merge pull request #85 from prathamesh920/marks_csv_dump
A moderator can download csv file for a given question paper.
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py17
-rw-r--r--yaksh/templates/yaksh/monitor.html1
-rw-r--r--yaksh/urls.py2
-rw-r--r--yaksh/views.py45
4 files changed, 65 insertions, 0 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 1bbd035..7bd0a9e 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -414,6 +414,23 @@ class AnswerPaperManager(models.Manager):
question_stats[question] = [0, questions[question.id]]
return question_stats
+ def get_answerpapers_for_quiz(self, questionpaper_id):
+ return self.filter(question_paper_id=questionpaper_id)
+
+ def _get_answerpapers_users(self, answerpapers):
+ return answerpapers.values_list('user', flat=True).distinct()
+
+ def get_latest_attempts(self, questionpaper_id):
+ papers = self.get_answerpapers_for_quiz(questionpaper_id)
+ users = self._get_answerpapers_users(papers)
+ latest_attempts = []
+ for user in users:
+ latest_attempts.append(self._get_latest_attempt(papers, user))
+ return latest_attempts
+
+ def _get_latest_attempt(self, answerpapers, user_id):
+ return answerpapers.filter(user_id=user_id).order_by('-attempt_number')[0]
+
###############################################################################
class AnswerPaper(models.Model):
diff --git a/yaksh/templates/yaksh/monitor.html b/yaksh/templates/yaksh/monitor.html
index cb14ba5..b81c9f2 100644
--- a/yaksh/templates/yaksh/monitor.html
+++ b/yaksh/templates/yaksh/monitor.html
@@ -40,6 +40,7 @@
{% if papers %}
<p>Number of papers: {{ papers|length }} </p>
<p><a href="{{URL_ROOT}}/exam/manage/statistics/question/{{papers.0.question_paper.id}}">Question Statisitics</a></p>
+<p><a href="{{URL_ROOT}}/exam/manage/monitor/download_csv/{{papers.0.question_paper.id}}">Download CSV</a></p>
<table border="1" cellpadding="3">
<tr>
<th> Name </th>
diff --git a/yaksh/urls.py b/yaksh/urls.py
index d74e244..be33051 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -65,6 +65,8 @@ urlpatterns += patterns('yaksh.views',
'show_statistics'),
url(r'^manage/statistics/question/(?P<questionpaper_id>\d+)/(?P<attempt_number>\d+)/$',
'show_statistics'),
+ url(r'^manage/monitor/download_csv/(?P<questionpaper_id>\d+)/$',
+ 'download_csv'),
url(r'manage/courses/$', 'courses'),
url(r'manage/add_course/$', 'add_course'),
url(r'manage/course_detail/(?P<course_id>\d+)/$', 'course_detail'),
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.