From 4c05c6cc18b4973bb158f978517eccb179fa7f75 Mon Sep 17 00:00:00 2001 From: Inga Kirschnick Date: Mon, 13 Mar 2023 15:04:44 +0100 Subject: [PATCH] merge settings into users route --- app/__init__.py | 3 - app/admin/routes.py | 2 +- app/settings/__init__.py | 5 -- app/settings/forms.py | 43 ----------- app/settings/routes.py | 39 ---------- app/templates/_navbar.html.j2 | 3 +- app/templates/_sidenav.html.j2 | 3 +- app/templates/settings/_breadcrumbs.html.j2 | 6 -- app/templates/settings/settings.html.j2 | 84 --------------------- app/templates/users/edit_profile.html.j2 | 77 +++++++++++++++++-- app/templates/users/edit_profile.js.j2 | 5 ++ app/users/forms.py | 43 ++++++++++- app/users/routes.py | 36 ++++++++- 13 files changed, 157 insertions(+), 192 deletions(-) delete mode 100644 app/settings/__init__.py delete mode 100644 app/settings/forms.py delete mode 100644 app/settings/routes.py delete mode 100644 app/templates/settings/_breadcrumbs.html.j2 delete mode 100644 app/templates/settings/settings.html.j2 diff --git a/app/__init__.py b/app/__init__.py index dcb58e47..09e479a8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -81,9 +81,6 @@ def create_app(config: Config = Config) -> Flask: from .services import bp as services_blueprint app.register_blueprint(services_blueprint, url_prefix='/services') - from .settings import bp as settings_blueprint - app.register_blueprint(settings_blueprint, url_prefix='/settings') - from .users import bp as users_blueprint app.register_blueprint(users_blueprint, url_prefix='/users') diff --git a/app/admin/routes.py b/app/admin/routes.py index 08f219ab..95ce7730 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -4,7 +4,7 @@ from threading import Thread from app import db, hashids from app.decorators import admin_required from app.models import Role, User, UserSettingJobStatusMailNotificationLevel -from app.settings.forms import ( +from app.users.forms import ( EditNotificationSettingsForm ) from app.users.forms import EditProfileSettingsForm diff --git a/app/settings/__init__.py b/app/settings/__init__.py deleted file mode 100644 index 1dab5142..00000000 --- a/app/settings/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from flask import Blueprint - - -bp = Blueprint('settings', __name__) -from . import routes # noqa diff --git a/app/settings/forms.py b/app/settings/forms.py deleted file mode 100644 index e90d9dda..00000000 --- a/app/settings/forms.py +++ /dev/null @@ -1,43 +0,0 @@ -from flask_wtf import FlaskForm -from wtforms import PasswordField, SelectField, SubmitField, ValidationError -from wtforms.validators import DataRequired, EqualTo -from app.models import UserSettingJobStatusMailNotificationLevel - - -class ChangePasswordForm(FlaskForm): - password = PasswordField('Old password', validators=[DataRequired()]) - new_password = PasswordField( - 'New password', - validators=[ - DataRequired(), - EqualTo('new_password_2', message='Passwords must match') - ] - ) - new_password_2 = PasswordField( - 'New password confirmation', - validators=[ - DataRequired(), - EqualTo('new_password', message='Passwords must match') - ] - ) - submit = SubmitField() - - def __init__(self, user, *args, **kwargs): - super().__init__(*args, **kwargs) - self.user = user - - def validate_current_password(self, field): - if not self.user.verify_password(field.data): - raise ValidationError('Invalid password') - - -class EditNotificationSettingsForm(FlaskForm): - job_status_mail_notification_level = SelectField( - 'Job status mail notification level', - choices=[ - (x.name, x.name.capitalize()) - for x in UserSettingJobStatusMailNotificationLevel - ], - validators=[DataRequired()] - ) - submit = SubmitField() diff --git a/app/settings/routes.py b/app/settings/routes.py deleted file mode 100644 index a07869b8..00000000 --- a/app/settings/routes.py +++ /dev/null @@ -1,39 +0,0 @@ -from flask import flash, redirect, render_template, url_for -from flask_login import current_user, login_required -from app import db -from app.models import UserSettingJobStatusMailNotificationLevel -from . import bp -from .forms import ChangePasswordForm, EditNotificationSettingsForm - - -@bp.route('', methods=['GET', 'POST']) -@login_required -def settings(): - change_password_form = ChangePasswordForm( - current_user, - prefix='change-password-form' - ) - edit_notification_settings_form = EditNotificationSettingsForm( - data=current_user.to_json_serializeable(), - prefix='edit-notification-settings-form' - ) - # region handle change_password_form POST - if change_password_form.submit.data and change_password_form.validate(): - current_user.password = change_password_form.new_password.data - db.session.commit() - flash('Your changes have been saved') - return redirect(url_for('.settings')) - # endregion handle change_password_form POST - # region handle edit_notification_settings_form POST - if edit_notification_settings_form.submit and edit_notification_settings_form.validate(): - current_user.setting_job_status_mail_notification_level = edit_notification_settings_form.job_status_mail_notification_level.data - db.session.commit() - flash('Your changes have been saved') - return redirect(url_for('.settings')) - # endregion handle edit_notification_settings_form POST - return render_template( - 'settings/settings.html.j2', - change_password_form=change_password_form, - edit_notification_settings_form=edit_notification_settings_form, - title='Settings' - ) diff --git a/app/templates/_navbar.html.j2 b/app/templates/_navbar.html.j2 index d943c0e4..c4c4d3b7 100644 --- a/app/templates/_navbar.html.j2 +++ b/app/templates/_navbar.html.j2 @@ -29,8 +29,7 @@