def post(self): """Handles POST requests.""" user = self.personalize_page_and_get_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return if not self.assert_xsrf_token_or_fail(self.request, 'register-post'): return can_register = self.app_context.get_environ( )['reg_form']['can_register'] if not can_register: self.template_value['course_status'] = 'full' else: name = self.request.get('form01') # create new or re-enroll old student student = Student.get_by_email(user.email()) if not student: student = Student(key_name=user.email()) student.user_id = user.user_id() student.is_enrolled = True student.name = name student.put() # Render registration confirmation page self.template_value['navbar'] = {'registration': True} self.render('confirmation.html')
def post(self): """Handles POST requests.""" user = self.personalize_page_and_get_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return if not self.assert_xsrf_token_or_fail(self.request, 'register-post'): return can_register = self.app_context.get_environ( )['reg_form']['can_register'] if not can_register: self.template_value['course_status'] = 'full' else: name = self.request.get('form01') surname = self.request.get('form02') age = self.request.get('form03') # create new or re-enroll old student student = Student.get_by_email(user.email()) if not student: student = Student(key_name=user.email()) student.user_id = user.user_id() student.is_enrolled = False student.name = name student.surname = surname student.age = age student.put() # Render registration confirmation page self.template_value['navbar'] = {'registration': True} self.render('confirmation.html')
def post(self): """Handles POST requests.""" user = self.personalize_page_and_get_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return if not self.assert_xsrf_token_or_fail(self.request, "register-post"): return can_register = self.app_context.get_environ()["reg_form"]["can_register"] if not can_register: self.template_value["course_status"] = "full" else: name = self.request.get("form01") # create new or re-enroll old student student = Student.get_by_email(user.email()) if not student: student = Student(key_name=user.email()) student.user_id = user.user_id() student.is_enrolled = True student.name = name student.put() # Render registration confirmation page self.template_value["navbar"] = {"registration": True} self.render("confirmation.html")
def post(self): """Handles POST requests.""" user = self.personalize_page_and_get_user() if not user: self.redirect(users.create_login_url(self.request.uri), normalize=False) return if not self.assert_xsrf_token_or_fail(self.request, 'register-post'): return can_register = self.app_context.get_environ( )['reg_form']['can_register'] if not can_register: self.template_value['course_status'] = 'full' else: name = self.request.get('form01') additional_fields = transforms.dumps(self.request.POST.items()) # create new or re-enroll old student student = Student.get_by_email(user.email()) if not student: student = Student(key_name=user.email()) student.user_id = user.user_id() student_by_uid = Student.get_student_by_user_id(user.user_id()) is_valid_student = (student_by_uid is None or student_by_uid.user_id == student.user_id) assert is_valid_student, ( 'Student\'s email and user id do not match.') student.user_id = user.user_id() student.is_enrolled = True student.name = name student.age = self.request.get('form02') student.additional_fields = additional_fields student.put() # Render registration confirmation page self.template_value['navbar'] = {'registration': True} self.render('confirmation.html')
def create_or_enroll_student(self, user, name): # create new or re-enroll old student student = Student.get_by_email(user.email()) if not student: student = Student(key_name=user.email()) student.user_id = user.user_id() # Add to global student namespace = namespace_manager.get_namespace() try: namespace_manager.set_namespace("") global_student = Student(key_name=user.email()) global_student.user_id = user.user_id() global_student.name = name global_student.put() finally: namespace_manager.set_namespace(namespace) student.is_enrolled = True student.name = name student.put()
def post(self): """Handles POST requests.""" user = self.personalize_page_and_get_user() if not user: self.redirect( users.create_login_url(self.request.uri), normalize=False) return if not self.assert_xsrf_token_or_fail(self.request, 'register-post'): return can_register = self.app_context.get_environ( )['reg_form']['can_register'] if not can_register: self.template_value['course_status'] = 'full' else: name = self.request.get('form01') additional_fields = transforms.dumps(self.request.POST.items()) # create new or re-enroll old student student = Student.get_by_email(user.email()) if not student: student = Student(key_name=user.email()) student.user_id = user.user_id() student_by_uid = Student.get_student_by_user_id(user.user_id()) is_valid_student = (student_by_uid is None or student_by_uid.user_id == student.user_id) assert is_valid_student, ( 'Student\'s email and user id do not match.') student.user_id = user.user_id() student.is_enrolled = True student.name = name student.additional_fields = additional_fields student.put() # Render registration confirmation page self.template_value['navbar'] = {'registration': True} self.render('confirmation.html')
def post(self): """Handles POST requests.""" user = self.personalize_page_and_get_user() if not user: self.redirect(users.create_login_url(self.request.uri), normalize=False) return if not self.assert_xsrf_token_or_fail(self.request, "register-post"): return can_register = self.app_context.get_environ()["reg_form"]["can_register"] if not can_register: self.template_value["course_status"] = "full" else: name = self.request.get("form01") additional_fields = transforms.dumps(self.request.POST.items()) # create new or re-enroll old student student = Student.get_by_email(user.email()) if not student: student = Student(key_name=user.email()) student.user_id = user.user_id() student_by_uid = Student.get_student_by_user_id(user.user_id()) is_valid_student = student_by_uid is None or student_by_uid.user_id == student.user_id assert is_valid_student, "Student's email and user id do not match." student.user_id = user.user_id() student.is_enrolled = True student.name = name student.age = self.request.get("formAge") student.additional_fields = additional_fields student.put() # Render registration confirmation page self.template_value["navbar"] = {"registration": True} self.render("confirmation.html")
def post(self): """Handles POST requests.""" user = self.personalize_page_and_get_user() if not user: self.redirect( users.create_login_url(self.request.uri), normalize=False) return if not self.assert_xsrf_token_or_fail(self.request, 'register-post'): return can_register = self.app_context.get_environ( )['reg_form']['can_register'] if not can_register: self.template_value['course_status'] = 'full' else: missing = self.find_missing_fields(self.request.POST) if missing: self.template_value['navbar'] = {'registration': True} self.template_value['content'] = ''' <div class="gcb-col-11 gcb-aside"> <h2>Something is missing...</h2> <p>You didn't fill out all the required fields in the registration form. Please use your browser's BACK button, and complete the form before submitting.</p> <p>Missing: {0}</p> <p>Thanks!</p> </div> '''.format(", ".join(missing)) self.render('bare.html') return # We accept the form. Now populate the student model: # create new or re-enroll old student student = Student.get_by_email(user.email()) if not student: student = Student(key_name=user.email()) student.user_id = user.user_id() student_by_uid = Student.get_student_by_user_id(user.user_id()) is_valid_student = (student_by_uid is None or student_by_uid.user_id == student.user_id) assert is_valid_student, ( 'Student\'s email and user id do not match.') student.user_id = user.user_id() student.is_enrolled = True string_fields = ('name', 'location_city', 'location_state', 'location_country', 'education_level', 'role', 'other_role') for field in string_fields: setattr(student, field, self.request.POST.get(field, None)) string_list_fields = ('grade_levels', 'title_and_setting', 'research_area', 'faculty_area', 'student_subject') for field in string_list_fields: raw = self.request.POST.get(field, '') if len(raw) > 0: values = [s.strip() for s in raw.split(',')] setattr(student, field, values) student.put() # now that we're in full registration, don't subscribe to pre-reg any more #mailchimp.subscribe('pre-reg', user.email(), student.name) self.redirect('confirm') return # Render registration confirmation page self.template_value['navbar'] = {'registration': True} self.render('confirmation.html')