diff options
author | Prabhu Ramachandran | 2011-12-01 16:22:54 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2011-12-01 16:22:54 +0530 |
commit | 6755a1604094e601fc6df88929841b5a06690c90 (patch) | |
tree | 6157ffd15c2f44e2df0e7a6b63077f02f23d5e99 /exam | |
parent | ca63bd41c8ae023e30eed73e5afd878d7bba4e96 (diff) | |
download | online_test-6755a1604094e601fc6df88929841b5a06690c90.tar.gz online_test-6755a1604094e601fc6df88929841b5a06690c90.tar.bz2 online_test-6755a1604094e601fc6df88929841b5a06690c90.zip |
Clean up question template and speed up monitor
For a bash question we now put a #!/bin/bash at the top.
We now use annotations to speed up the monitor page rendering rather
than doing the sort in Python which ends up being inefficient due to the
db calls. I get a roughly 5x improvement in speed.
Diffstat (limited to 'exam')
-rw-r--r-- | exam/views.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/exam/views.py b/exam/views.py index 892b35f..c178a0b 100644 --- a/exam/views.py +++ b/exam/views.py @@ -9,6 +9,7 @@ from django.contrib.auth import login, logout, authenticate from django.shortcuts import render_to_response, get_object_or_404, redirect from django.template import RequestContext from django.http import Http404 +from django.db.models import Sum # Local imports. from exam.models import Quiz, Question, QuestionPaper, Profile, Answer, User @@ -262,6 +263,7 @@ def complete(request, reason=None): else: return my_redirect('/exam/') + def monitor(request, quiz_id=None): """Monitor the progress of the papers taken so far.""" user = request.user @@ -282,12 +284,8 @@ def monitor(request, quiz_id=None): papers = [] quiz = None else: - papers = QuestionPaper.objects.filter(quiz=quiz, - user__profile__isnull=False) - - papers = sorted(papers, - cmp=lambda x, y: cmp(x.get_total_marks(), y.get_total_marks()), - reverse=True) + papers = QuestionPaper.objects.all().annotate( + total=Sum('answers__marks')).order_by('-total') context = {'papers': papers, 'quiz': quiz, 'quizzes': None} return my_render_to_response('exam/monitor.html', context, |