Exemplo n.º 1
0
def getQuestion(genre):
    """to get a question by genre"""
    if not genre:
        genre = "general"
    questions = getQuestionKeys(genre)
    if not questions:
        logging.error("dbfunc.py line 39: couldn't return a question for: " + genre)
        questions = getQuestionKeys("general")
    ranChoice = random.choice(questions)
    # not in cache get from db set cache
    q = memg(str(ranChoice))
    if not q:
        q = db.get(ranChoice)
        mems(str(ranChoice), q)
    q = q.asDict()
    options = [q["answer"], q["choice1"], q["choice2"], q["choice3"]]
    random.shuffle(options)
    q["options"] = options
    q["hashed"] = makeCookieHash(q["answer"])
    return q
Exemplo n.º 2
0
 def setCookie(self, username):
     cookieVal = "%s:%s" % (str(username), str(makeCookieHash(username)))
     self.response.set_cookie('user', cookieVal)
Exemplo n.º 3
0
 def setCookie(self, name, value):
     '''set a cookie with a value and a hash of the value'''
     #get the value back with testCookie(name)
     cookieVal = "%s:%s" % (str(value), str(makeCookieHash(value)))
     self.response.set_cookie(name, cookieVal)
Exemplo n.º 4
0
Arquivo: envdef.py Projeto: Mb01/yasai
 def setCookie(self, username):
     cookieVal = "%s:%s" % (str(username), str(makeCookieHash(username)))
     self.response.set_cookie('user', cookieVal)