summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrabhu Ramachandran2011-12-01 16:22:54 +0530
committerPrabhu Ramachandran2011-12-01 16:22:54 +0530
commit6755a1604094e601fc6df88929841b5a06690c90 (patch)
tree6157ffd15c2f44e2df0e7a6b63077f02f23d5e99
parentca63bd41c8ae023e30eed73e5afd878d7bba4e96 (diff)
downloadonline_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.
-rw-r--r--exam/views.py10
-rw-r--r--templates/exam/question.html2
2 files changed, 5 insertions, 7 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,
diff --git a/templates/exam/question.html b/templates/exam/question.html
index 62b8b3d..8b589b6 100644
--- a/templates/exam/question.html
+++ b/templates/exam/question.html
@@ -65,7 +65,7 @@ function update_time()
<input name="answer" type="radio" value="{{option}}" />{{option}} <br/>
{% endfor %}
{% else %}
-<textarea rows="20" cols="100" name="answer">{% if last_attempt %}{{last_attempt.strip}}{% else %}# Enter your answer here.{% endif %}</textarea>
+<textarea rows="20" cols="100" name="answer">{% if last_attempt %}{{last_attempt.strip}}{% else %}{% if question.type == "bash" %}#!/bin/bash{% else %}# Enter your answer here.{% endif %}{% endif %}</textarea>
{% endif %}
<br/>
{% if question.type == "mcq" %}