# HG changeset patch
# User nishanth
# Date 1271867013 -19800
# Node ID 0fa055b8ea9876e4eaa4b3e386348327ec109b17
# Parent 307c6887cc67213d597697657d4be1faeacebeaf
implemented correct_quiz function and added it at the time of closing quiz and modified question bank
diff -r 307c6887cc67 -r 0fa055b8ea98 event/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]})
diff -r 307c6887cc67 -r 0fa055b8ea98 offline.db.bak
Binary file offline.db.bak has changed
diff -r 307c6887cc67 -r 0fa055b8ea98 question_bank.xml
--- 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)?
-30
+90
xlim \( 0 , 2 \* pi \) [;,\n+] ylim \( -1.5 , 1.5\)
@@ -35,7 +35,8 @@
30
-(line\.split \( ([",']) , \2 \))
+line\.split \( \" , \" \)
+line\.split \( \' , \' \)
@@ -47,7 +48,7 @@
30
-len \( a \)
+len \( a \)
diff -r 307c6887cc67 -r 0fa055b8ea98 quiz/models.py
--- 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.
diff -r 307c6887cc67 -r 0fa055b8ea98 quiz/utils.py
--- 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.
+"""
+
diff -r 307c6887cc67 -r 0fa055b8ea98 quiz/views.py
--- 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)