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
def setCookie(self, username): cookieVal = "%s:%s" % (str(username), str(makeCookieHash(username))) self.response.set_cookie('user', cookieVal)
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)