示例#1
0
文件: dbfunc.py 项目: Mb01/playground
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
示例#2
0
 def setCookie(self, username):
     cookieVal = "%s:%s" % (str(username), str(makeCookieHash(username)))
     self.response.set_cookie('user', cookieVal)
示例#3
0
文件: envdef.py 项目: Mb01/playground
 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)
示例#4
0
文件: envdef.py 项目: Mb01/yasai
 def setCookie(self, username):
     cookieVal = "%s:%s" % (str(username), str(makeCookieHash(username)))
     self.response.set_cookie('user', cookieVal)