def get_create_student(name='Anonymous'): student = get_student() if student: return (student, False) else: return (Student.create(name=name, session_id=random_student_id()), True)
def get_student(): student_id = request.cookies.get('student_id') if student_id: students = Student.select().where(Student.session_id == student_id) for s in students: return s return None
def random_student_id(): while True: student_id = "".join([random.choice(string.ascii_letters + string.digits) for n in xrange(32)]) students = Student.select().where(Student.session_id == student_id) for student in students: break else: return student_id
def random_student_id(): while True: student_id = "".join([ random.choice(string.ascii_letters + string.digits) for n in xrange(32) ]) students = Student.select().where(Student.session_id == student_id) for student in students: break else: return student_id