From 812f79bd79c54b3b362ef616c121fb500b0b8a11 Mon Sep 17 00:00:00 2001 From: Prabhu Ramachandran Date: Thu, 10 Nov 2011 14:47:22 +0530 Subject: ENH: Adding a monitor page to see results Adds a simple /exam/monitor page that displays current quiz results. --- exam/views.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'exam/views.py') diff --git a/exam/views.py b/exam/views.py index 0dc02cc..2a79b24 100644 --- a/exam/views.py +++ b/exam/views.py @@ -162,4 +162,28 @@ def complete(request): return render_to_response('exam/complete.html') else: return redirect('/exam/') - + +def monitor(request): + """Monitor the progress of the quizzes taken so far.""" + quizzes = Quiz.objects.all() + questions = Question.objects.all() + # Mapping from question id to points + marks = dict( ( (q.id, q.points) for q in questions) ) + quiz_list = [] + for quiz in quizzes: + paper = {} + user = quiz.user + paper['username'] = str(user.first_name) + ' ' + str(user.last_name) + qa = quiz.questions_answered.split('|') + answered = ', '.join(sorted(qa)) + paper['answered'] = answered if answered else 'None' + total = sum( [marks[int(id)] for id in qa if id] ) + paper['total'] = total + quiz_list.append(paper) + + quiz_list.sort(cmp=lambda x, y: cmp(x['total'], y['total']), + reverse=True) + + context = {'quiz_list': quiz_list} + return render_to_response('exam/monitor.html', context, + context_instance=RequestContext(request)) -- cgit