summaryrefslogtreecommitdiff
path: root/exam
diff options
context:
space:
mode:
authorPrabhu Ramachandran2011-11-10 14:47:22 +0530
committerPrabhu Ramachandran2011-11-10 14:47:22 +0530
commit812f79bd79c54b3b362ef616c121fb500b0b8a11 (patch)
tree96289a3e2c33a453a9b290f6acd76464e213551c /exam
parent6cf7eb9f1a69f596ea0dcc418c1b90d3fb8ec513 (diff)
downloadonline_test-812f79bd79c54b3b362ef616c121fb500b0b8a11.tar.gz
online_test-812f79bd79c54b3b362ef616c121fb500b0b8a11.tar.bz2
online_test-812f79bd79c54b3b362ef616c121fb500b0b8a11.zip
ENH: Adding a monitor page to see results
Adds a simple /exam/monitor page that displays current quiz results.
Diffstat (limited to 'exam')
-rw-r--r--exam/urls.py1
-rw-r--r--exam/views.py26
2 files changed, 26 insertions, 1 deletions
diff --git a/exam/urls.py b/exam/urls.py
index cfb4764..1ca9755 100644
--- a/exam/urls.py
+++ b/exam/urls.py
@@ -5,6 +5,7 @@ urlpatterns = patterns('exam.views',
url(r'^start/$', 'start'),
url(r'^quit/$', 'quit'),
url(r'^complete/$', 'complete'),
+ url(r'^monitor/$', 'monitor'),
url(r'^(?P<q_id>\d+)/$', 'question'),
url(r'^(?P<q_id>\d+)/check/$', 'check'),
)
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))