From 575eeae94a8034f1348c8b932810a3adccb6ae9d Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Mon, 20 Mar 2023 16:00:25 +0100 Subject: [PATCH] Fix errors from settings move --- app/settings/routes.py | 26 +++++++------------ app/templates/_navbar.html.j2 | 2 +- app/templates/_sidenav.html.j2 | 2 +- ...{edit_profile.html.j2 => settings.html.j2} | 5 ++-- app/users/__init__.py | 2 +- app/users/routes.py | 1 - 6 files changed, 16 insertions(+), 22 deletions(-) rename app/templates/settings/{edit_profile.html.j2 => settings.html.j2} (98%) diff --git a/app/settings/routes.py b/app/settings/routes.py index bc36a9c8..a4e1e124 100644 --- a/app/settings/routes.py +++ b/app/settings/routes.py @@ -7,9 +7,8 @@ from flask import ( ) from flask_breadcrumbs import register_breadcrumb from flask_login import current_user, login_required -import os from app import db -from app.models import Avatar, Corpus, ProfilePrivacySettings, User +from app.models import Avatar, ProfilePrivacySettings from . import bp from .forms import ( ChangePasswordForm, @@ -17,16 +16,12 @@ from .forms import ( EditProfileSettingsForm, EditPublicProfileInformationForm ) -from .utils import user_endpoint_arguments_constructor as user_eac -@bp.route('//edit', methods=['GET', 'POST']) -@register_breadcrumb(bp, 'breadcrumbs.settings', 'settingsSettings', endpoint_arguments_constructor=user_eac) +@bp.route('', methods=['GET', 'POST']) +@register_breadcrumb(bp, '.', 'settingsSettings') @login_required -def edit_profile(user_id): - user = User.query.get_or_404(user_id) - if not (user == current_user or current_user.is_administrator()): - abort(403) +def settings(): # region forms edit_profile_settings_form = EditProfileSettingsForm( current_user, @@ -52,7 +47,7 @@ def edit_profile(user_id): current_user.username = edit_profile_settings_form.username.data db.session.commit() flash('Profile settings updated') - return redirect(url_for('users.user', user_id=user.id)) + return redirect(url_for('.settings')) # endregion handle edit profile settings forms # region handle edit public profile information form if edit_public_profile_information_form.submit.data and edit_public_profile_information_form.validate(): @@ -80,29 +75,28 @@ def edit_profile(user_id): current_user.website = edit_public_profile_information_form.website.data current_user.full_name = edit_public_profile_information_form.full_name.data db.session.commit() - flash('Profile settings updated') - return redirect(url_for('users.user', user_id=user.id)) + flash('Your changes have been saved') + return redirect(url_for('.settings')) # endregion handle edit public profile information 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('.edit_profile', user_id=user.id)) + 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('.edit_profile', user_id=user.id)) + return redirect(url_for('.settings')) # endregion handle edit_notification_settings_form POST return render_template( - 'settings/edit_profile.html.j2', + 'settings/settings.html.j2', edit_profile_settings_form=edit_profile_settings_form, edit_public_profile_information_form=edit_public_profile_information_form, change_password_form=change_password_form, edit_notification_settings_form=edit_notification_settings_form, - user=user, title='Settings' ) diff --git a/app/templates/_navbar.html.j2 b/app/templates/_navbar.html.j2 index 00dd7700..61adaee5 100644 --- a/app/templates/_navbar.html.j2 +++ b/app/templates/_navbar.html.j2 @@ -33,7 +33,7 @@