def get_student(coach, request_handler): student = request_handler.request_user_data("student_email") if student is None: raise Exception("No student found with email='%s'." % request_handler.request_string("student_email")) if not student.is_coached_by(coach): raise Exception("Not your student!") return student
def get_list(coach, request_handler): list_id = request_handler.request_string('list_id') student_list = StudentList.get(list_id) if student_list is None: raise Exception("No list found with list_id='%s'." % list_id) if coach.key() not in student_list.coaches: raise Exception("Not your list!") return student_list
def get_student(coach, request_handler): student = request_handler.request_user_data('student_email') if student is None: raise Exception("No student found with email='%s'." % request_handler.request_string('student_email')) if not student.is_coached_by(coach): raise Exception("Not your student!") return student
def get_list(coach, request_handler): list_id = request_handler.request_string("list_id") student_list = StudentList.get(list_id) if student_list is None: raise Exception("No list found with list_id='%s'." % list_id) if coach.key() not in student_list.coaches: raise Exception("Not your list!") return student_list
def get_last_student_list(request_handler, student_lists, use_cookie=True): student_lists = student_lists.fetch(100) # default_list is the default list for this user if student_lists: default_list = str(student_lists[0].key()) else: default_list = 'allstudents' # desired list is the list the user asked for (via cookie or querystring) desired_list = None if use_cookie: cookie_val = request_handler.get_cookie_value('studentlist_id') desired_list = cookie_val or desired_list # override cookie with explicitly set querystring desired_list = request_handler.request_string('list_id', desired_list) # now validate desired_list exists current_list = None list_id = 'allstudents' if desired_list != 'allstudents': for s in student_lists: if str(s.key()) == desired_list: current_list = s list_id = desired_list break if current_list is None: list_id = default_list if use_cookie: request_handler.set_cookie('studentlist_id', list_id, max_age=2629743) return list_id, current_list
def get_coach_student_and_student_list(request_handler): coach = UserData.current() student_list = get_student_list(coach, request_handler.request_string("list_id")) student = get_student(coach, request_handler) return (coach, student, student_list)