implemented correct_quiz function and added it at the time of closing quiz and modified question bank
authornishanth
Wed, 21 Apr 2010 21:53:33 +0530
changeset 39 0fa055b8ea98
parent 38 307c6887cc67
child 40 89d29b1c42b5
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
event/views.py
offline.db.bak
question_bank.xml
quiz/models.py
quiz/utils.py
quiz/views.py
--- a/event/views.py	Wed Apr 21 19:52:51 2010 +0530
+++ b/event/views.py	Wed Apr 21 21:53:33 2010 +0530
@@ -1,9 +1,12 @@
 from django.http import Http404
 from django.shortcuts import render_to_response, redirect
 
+from offline.settings import ADMIN_KEY
+
 from offline.event.models import Event
 from offline.event.forms import EventCreateForm
-from offline.settings import ADMIN_KEY
+
+from offline.quiz.utils import correct_quiz
 
 num2name = {"11" : "Day 1 Quiz 1",
             "12" : "Day 1 Quiz 2",
@@ -113,5 +116,9 @@
     event.quiz_status = "00"
     event.save()
 
+    event_quizzes = event.quiz.filter(quiz_num=quiz_num)
+    for quiz in event_quizzes:
+        correct_quiz(quiz)
+
     return render_to_response("close_quiz.html", {"admin_key":ADMIN_KEY, "quiz_name":num2name[quiz_num]})
 
Binary file offline.db.bak has changed
--- a/question_bank.xml	Wed Apr 21 19:52:51 2010 +0530
+++ b/question_bank.xml	Wed Apr 21 21:53:33 2010 +0530
@@ -6,7 +6,7 @@
 How will you set the x and y axis limits so that the region of interest is in the rectangle (0, -1.5) and (2\pi, 1.5)?
 </description>
 <time_limit>
-30
+90
 </time_limit>
 <expected_answer>
 xlim \( 0 , 2 \* pi \) [;,\n+] ylim \( -1.5 , 1.5\)
@@ -35,7 +35,8 @@
 30
 </time_limit>
 <expected_answer>
-(line\.split \( ([",']) , \2 \))
+line\.split \( \" , \" \)
+line\.split \( \' , \' \)
 </expected_answer>
 </question>
 
@@ -47,7 +48,7 @@
 30
 </time_limit>
 <expected_answer>
-len \( a \) 
+len \( a \)
 </expected_answer>
 </question>
 
--- a/quiz/models.py	Wed Apr 21 19:52:51 2010 +0530
+++ b/quiz/models.py	Wed Apr 21 21:53:33 2010 +0530
@@ -29,7 +29,7 @@
 
     question = models.ForeignKey(QuestionBank)
     submitted_ans = models.TextField()
-    is_correct = models.BooleanField()
+    is_correct = models.BooleanField(default=False)
 
 class Quiz(models.Model):
     """ A model to hold the proceeding of a quiz.
--- a/quiz/utils.py	Wed Apr 21 19:52:51 2010 +0530
+++ b/quiz/utils.py	Wed Apr 21 21:53:33 2010 +0530
@@ -1,6 +1,30 @@
 import string
 import random
+import re
 
 def gen_key(no_of_chars):
     allowed_chars = string.digits+string.uppercase
     return ''.join([random.choice(allowed_chars) for i in range(no_of_chars)])
+
+def correct_quiz(quiz):
+    """ read each submitted answer and update the is_correct variable.
+    """
+
+    for answer in quiz.que_answered.all():
+
+        expected_ans = answer.question.expected_ans
+
+        ans_regex_patterns = [ r"\s*".join(ans_pattern.split()) for ans_pattern in expected_ans.split("\n") ]
+        for pattern in ans_regex_patterns:
+            if re.findall(pattern, answer.submitted_ans):
+                answer.is_correct = True
+                answer.save()
+                break
+
+"""
+we send quiz objects filtered by event and quiz num one by and update answer objects in all corresponding answers
+later while retreving, we filter on user also ( for displaying in the table)
+the table is by default in sorted fashion and also has the links.
+seperate table for each quiz.
+"""
+
--- a/quiz/views.py	Wed Apr 21 19:52:51 2010 +0530
+++ b/quiz/views.py	Wed Apr 21 21:53:33 2010 +0530
@@ -161,7 +161,7 @@
         except MultiValueDictKeyError:
             answer = ""
         new_answer = Answer(question=question)
-        new_answer.submitted_ans = answer
+        new_answer.submitted_ans = answer.strip()
         new_answer.save()
 
         quiz.que_answered.add(new_answer)