mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 17:25:44 +00:00
59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
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,
|
|
EditGeneralSettingsForm,
|
|
EditNotificationSettingsForm
|
|
)
|
|
|
|
|
|
@bp.route('', methods=['GET', 'POST'])
|
|
@login_required
|
|
def settings():
|
|
change_password_form = ChangePasswordForm(
|
|
current_user,
|
|
prefix='change-password-form'
|
|
)
|
|
edit_general_settings_form = EditGeneralSettingsForm(
|
|
current_user,
|
|
data=current_user.to_json_serializeable(),
|
|
prefix='edit-general-settings-form'
|
|
)
|
|
edit_notification_settings_form = EditNotificationSettingsForm(
|
|
data=current_user.to_json_serializeable(),
|
|
prefix='edit-notification-settings-form'
|
|
)
|
|
|
|
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('.index'))
|
|
if (edit_general_settings_form.submit.data
|
|
and edit_general_settings_form.validate()):
|
|
current_user.email = edit_general_settings_form.email.data
|
|
current_user.username = edit_general_settings_form.username.data
|
|
db.session.commit()
|
|
flash('Your changes have been saved')
|
|
return redirect(url_for('.settings'))
|
|
if (edit_notification_settings_form.submit.data
|
|
and edit_notification_settings_form.validate()):
|
|
current_user.setting_job_status_mail_notification_level = (
|
|
UserSettingJobStatusMailNotificationLevel[
|
|
edit_notification_settings_form.job_status_mail_notification_level.data # noqa
|
|
]
|
|
)
|
|
db.session.commit()
|
|
flash('Your changes have been saved')
|
|
return redirect(url_for('.settings'))
|
|
return render_template(
|
|
'settings/settings.html.j2',
|
|
change_password_form=change_password_form,
|
|
edit_general_settings_form=edit_general_settings_form,
|
|
edit_notification_settings_form=edit_notification_settings_form,
|
|
title='Settings'
|
|
)
|