quiz/utils.py
author nishanth
Wed, 21 Apr 2010 21:53:33 +0530
changeset 39 0fa055b8ea98
parent 12 81cd0140a0f2
child 40 89d29b1c42b5
permissions -rw-r--r--
implemented correct_quiz function and added it at the time of closing quiz and modified question bank

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.
"""