summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exam/urls.py1
-rw-r--r--exam/views.py26
-rw-r--r--templates/exam/monitor.html22
3 files changed, 48 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))
diff --git a/templates/exam/monitor.html b/templates/exam/monitor.html
new file mode 100644
index 0000000..21618e9
--- /dev/null
+++ b/templates/exam/monitor.html
@@ -0,0 +1,22 @@
+<h1> Current quiz results </h1>
+
+<meta http-equiv="refresh" content="30"/>
+
+{% if quiz_list %}
+<table border="1">
+ <tr>
+ <th>Student </th> <th>Questions answered</th> <th>Total marks</th>
+ </tr>
+ {% for paper in quiz_list %}
+ <tr>
+ <td>{{ paper.username }} </td>
+ <td>{{ paper.answered }} </td>
+ <td> {{ paper.total }} </td>
+
+ </tr>
+ {% endfor %}
+</table>
+{% else %}
+ <p> No quizzes so far. </p>
+{% endif %}
+