diff options
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 17 | ||||
-rw-r--r-- | yaksh/templates/yaksh/monitor.html | 1 | ||||
-rw-r--r-- | yaksh/urls.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 45 |
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 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. |