quiz/utils.py
changeset 39 0fa055b8ea98
parent 12 81cd0140a0f2
child 40 89d29b1c42b5
equal deleted inserted replaced
38:307c6887cc67 39:0fa055b8ea98
     1 import string
     1 import string
     2 import random
     2 import random
       
     3 import re
     3 
     4 
     4 def gen_key(no_of_chars):
     5 def gen_key(no_of_chars):
     5     allowed_chars = string.digits+string.uppercase
     6     allowed_chars = string.digits+string.uppercase
     6     return ''.join([random.choice(allowed_chars) for i in range(no_of_chars)])
     7     return ''.join([random.choice(allowed_chars) for i in range(no_of_chars)])
       
     8 
       
     9 def correct_quiz(quiz):
       
    10     """ read each submitted answer and update the is_correct variable.
       
    11     """
       
    12 
       
    13     for answer in quiz.que_answered.all():
       
    14 
       
    15         expected_ans = answer.question.expected_ans
       
    16 
       
    17         ans_regex_patterns = [ r"\s*".join(ans_pattern.split()) for ans_pattern in expected_ans.split("\n") ]
       
    18         for pattern in ans_regex_patterns:
       
    19             if re.findall(pattern, answer.submitted_ans):
       
    20                 answer.is_correct = True
       
    21                 answer.save()
       
    22                 break
       
    23 
       
    24 """
       
    25 we send quiz objects filtered by event and quiz num one by and update answer objects in all corresponding answers
       
    26 later while retreving, we filter on user also ( for displaying in the table)
       
    27 the table is by default in sorted fashion and also has the links.
       
    28 seperate table for each quiz.
       
    29 """
       
    30