def edit_profile(): form = EditProfileForm() if form.validate_on_submit(): # Update all basic information current_user.discord_name = form.discord_name.data current_user.pronunciation = form.pronunciation.data current_user.pronouns = form.pronouns.data current_user.about = form.about.data if form.has_runner_info() or current_user.runner_info is not None: form.runner_info_required = True if current_user.runner_info is None: current_user.runner_info = RunnerInfo() current_user.runner_info.twitch_name = form.twitch_name.data current_user.runner_info.srl_name = form.srl_name.data current_user.runner_info.src_name = form.src_name.data current_user.runner_info.input_method = form.input_method.data if form.has_volunteer_info( ) or current_user.volunteer_info is not None: if current_user.volunteer_info is None: current_user.volunteer_info = VolunteerInfo() current_user.volunteer_info.restream = form.restream.data == "yes" current_user.volunteer_info.commentary = form.commentary.data == "yes" current_user.volunteer_info.tracking = form.tracking.data == "yes" if form.new_password.data is not None and form.new_password.data is not "": current_user.set_password(form.new_password.data) db.session.commit() flash("Your profile has been updated.") return redirect(url_for("user", username=current_user.username)) elif request.method == "GET": # Populate form form.discord_name.data = current_user.discord_name form.pronunciation.data = current_user.pronunciation form.pronouns.data = current_user.pronouns form.about.data = current_user.about if current_user.runner_info is not None: form.runner_info_required() form.twitch_name.data = current_user.runner_info.twitch_name form.srl_name.data = current_user.runner_info.srl_name form.src_name.data = current_user.runner_info.src_name form.input_method.data = current_user.runner_info.input_method if current_user.volunteer_info is not None: form.restream.data = "yes" if current_user.volunteer_info.restream else "no" form.commentary.data = "yes" if current_user.volunteer_info.commentary else "no" form.tracking.data = "yes" if current_user.volunteer_info.tracking else "no" return render_template("edit_profile.html", title="Edit Profile", form=form)