From 61545ed4ecf3c917c22c101fa16e44231f0327a5 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Thu, 31 Oct 2019 13:19:18 +0100 Subject: [PATCH] Push one fix idea for multiple forms --- app/profile/forms.py | 4 ++-- app/profile/views.py | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/profile/forms.py b/app/profile/forms.py index 6bf4e996..ca6220be 100644 --- a/app/profile/forms.py +++ b/app/profile/forms.py @@ -1,9 +1,9 @@ from flask_wtf import FlaskForm from wtforms import (PasswordField, StringField, SubmitField, ValidationError, BooleanField) -from wtforms.validators import DataRequired, EqualTo, Length, Email +from wtforms.validators import DataRequired, EqualTo, Email from ..models import User -import logging + class ChangePasswordForm(FlaskForm): """ diff --git a/app/profile/views.py b/app/profile/views.py index a7832681..69b32ae6 100644 --- a/app/profile/views.py +++ b/app/profile/views.py @@ -45,14 +45,24 @@ def profile_change_password(): @login_required def profile_edit_user_info(): edit_user_info_form = EditProfileForm(user=current_user) - if not edit_user_info_form.validate_on_submit(): - abort(400) - current_user.email = edit_user_info_form.email.data - db.session.add(current_user._get_current_object()) - db.session.commit() - flash('Your email has been updated.') + if edit_user_info_form.validate_on_submit(): + current_user.email = edit_user_info_form.email.data + db.session.add(current_user._get_current_object()) + db.session.commit() + flash('Your email has been updated.') + else: + logger.warning('Form: {}'.format(edit_user_info_form.errors)) + return render_template('profile/index.html.j2', + change_password_form=ChangePasswordForm(), + edit_user_info_form=edit_user_info_form, + edit_user_settings_form=EditUserSettingsForm(), + title='Profile') edit_user_info_form.email.data = current_user.email - return redirect(url_for('profile.index')) + return render_template('profile/index.html.j2', + change_password_form=ChangePasswordForm(), + edit_user_info_form=EditProfileForm(user=current_user), + edit_user_settings_form=EditUserSettingsForm(), + title='Profile') @profile.route('/edit_user_settings', methods=['POST'])