def solutions(): """ Return solutions list from session """ session = get_request().session if not 'captcha_solutions' in session: session['captcha_solutions'] = {} return session['captcha_solutions']
def generate(): """ Generate random solution and save it in session. """ solution = random_word() captcha_id = hashlib.sha1(solution + settings.SECRET_KEY).hexdigest() solutions()[captcha_id] = solution # http://www.djangoproject.com/documentation/sessions/#when-sessions-are-saved get_request().session.modified = True return captcha_id