Exemple #1
0
 def save(self):
     if self.id is None:
         DESIRED_QUESTIONS = 20
         self.id = str(uuid4())
         all_questions = user_store.keys('question:*')
         all_questions = [int(x[9:]) for x in all_questions]
         if len(all_questions) < DESIRED_QUESTIONS:
             raise Exception("Not enough questions")
         random_questions = random.sample(all_questions, DESIRED_QUESTIONS)
         for q in random_questions:
             user_store.sadd('user_questions:' + self.id, q)
     user_store.hmset('user:'******'id': self.id,
         'name': self.name,
         'email': self.email,
         'branch': self.branch,
         'roll_no': self.roll_no,
         'score': self.score
     })
Exemple #2
0
 def complete_test(self):
     return user_store.sadd('test_completed_users', self.id)
Exemple #3
0
 def skip_question(self, form):
     qid = int(form.question.data)
     user_store.sadd('user_skipped_questions:' + self.id, qid)
Exemple #4
0
 def answer_question(self, form):
     qid = int(form.question.data)
     user_store.sadd('user_answered_questions:' + self.id, qid)
     user_store.hset('user_answers:' + self.id, qid, form.answer.data)
Exemple #5
0
import sys
import random
from mycq import user_store

if len(sys.argv) > 1:
    count = int(sys.argv[1])
else:
    count = 20

while count > 0:
    token = '{token:06d}'.format(token=random.randint(0, 999999))
    if user_store.sadd('signup_tokens', token) == 0:
        continue
    print token
    count -= 1