created a user_dump page that shows all the answers entered by user at one place
authornishanth
Thu, 22 Apr 2010 01:35:31 +0530
changeset 42 007d87112911
parent 41 d424b9668a74
child 43 265ed367e8cc
created a user_dump page that shows all the answers entered by user at one place
event/views.py
templates/list_toppers.html
urls.py
--- a/event/views.py	Thu Apr 22 00:36:08 2010 +0530
+++ b/event/views.py	Thu Apr 22 01:35:31 2010 +0530
@@ -145,5 +145,35 @@
     quizzes_with_scores = quizzes.annotate(score=Sum('que_answered__is_correct'))
     sorted_quizzes = quizzes_with_scores.order_by("score").reverse()
 
-    return render_to_response("list_toppers.html", {"sorted_quizzes":sorted_quizzes, "event":event, "quiz_name":num2name[quiz_num]})
+    return render_to_response("list_toppers.html", {"sorted_quizzes":sorted_quizzes,"admin_key":ADMIN_KEY, "event":event, "quiz_name":num2name[quiz_num]})
+
+def user_dump(request, admin_key, quiz_key, user_name):
+    """ check for admin_key
+    then get quiz by quiz_key and user_name.
+    then display the dump
+    """
+
+    if not admin_key == ADMIN_KEY:
+        raise Http404
 
+    try:
+        event = Event.objects.all()[0]
+    except IndexError:
+        return redirect('/event/create/%s'%ADMIN_KEY)
+    try:
+        quiz = Quiz.objects.get(event=event, key=quiz_key)
+    except Quiz.DoesNotExist:
+        raise Http404
+
+    if not quiz.user.username == user_name:
+        raise Http404
+
+    quiz_name = num2name[quiz.quiz_num]
+    if request.method == "POST":
+        for ans in quiz.que_answered.all():
+            ans.is_correct = True if str(ans.question.id) in request.POST else False
+            ans.save()
+        return redirect("/quiz/toppers/%s/%s"%(ADMIN_KEY, quiz.quiz_num))
+    else:
+        return render_to_response("user_dump.html", {"quiz":quiz, "quiz_name":quiz_name}) 
+
--- a/templates/list_toppers.html	Thu Apr 22 00:36:08 2010 +0530
+++ b/templates/list_toppers.html	Thu Apr 22 01:35:31 2010 +0530
@@ -10,7 +10,7 @@
 	</tr>
 	{% for quiz in sorted_quizzes %}
 	<tr align="center">
-			<td><a href="/quiz/ans_dump/{{admin_key}}/{{quiz.key}}/{{user.username}}">{{quiz.user.get_full_name}}</a></td>
+			<td><a href="/quiz/user_dump/{{admin_key}}/{{quiz.key}}/{{quiz.user.username}}">{{quiz.user.get_full_name}}</a></td>
 			<td>{{quiz.user.get_profile.profession}}</td>
 			<td>{{quiz.score}}</td>
 	</tr>
--- a/urls.py	Thu Apr 22 00:36:08 2010 +0530
+++ b/urls.py	Thu Apr 22 01:35:31 2010 +0530
@@ -38,4 +38,5 @@
     (r'^quiz/complete/$', quiz_views.quiz_complete),
 
     (r'^quiz/toppers/(\w+)/(\w+)$', event_views.list_toppers),
+    (r'^quiz/user_dump/(\w+)/(\w+)/(\w+)', event_views.user_dump),
 )