2020-11-13 09:01:51 +00:00
|
|
|
from flask import flash, redirect, render_template, url_for
|
2020-10-26 10:23:19 +00:00
|
|
|
from flask_login import current_user, login_required, logout_user
|
2021-09-13 09:45:43 +00:00
|
|
|
from . import bp, tasks
|
2022-02-08 11:26:20 +00:00
|
|
|
from .forms import (
|
|
|
|
ChangePasswordForm,
|
|
|
|
EditGeneralSettingsForm,
|
|
|
|
EditInterfaceSettingsForm,
|
|
|
|
EditNotificationSettingsForm
|
|
|
|
)
|
2020-10-23 11:52:01 +00:00
|
|
|
from .. import db
|
2022-02-09 15:02:37 +00:00
|
|
|
from ..models import UserSettingJobStatusMailNotificationLevel
|
2020-10-23 11:52:01 +00:00
|
|
|
|
|
|
|
|
2022-02-08 11:26:20 +00:00
|
|
|
@bp.route('', methods=['GET', 'POST'])
|
2020-10-23 11:52:01 +00:00
|
|
|
@login_required
|
|
|
|
def index():
|
2022-02-08 11:26:20 +00:00
|
|
|
change_password_form = ChangePasswordForm(
|
|
|
|
current_user._get_current_object(),
|
|
|
|
prefix='change_password_form'
|
|
|
|
)
|
|
|
|
edit_general_settings_form = EditGeneralSettingsForm(
|
|
|
|
current_user._get_current_object(),
|
|
|
|
prefix='edit_general_settings_form'
|
|
|
|
)
|
|
|
|
edit_interface_settings_form = EditInterfaceSettingsForm(
|
|
|
|
prefix='edit_interface_settings_form'
|
|
|
|
)
|
|
|
|
edit_notification_settings_form = EditNotificationSettingsForm(
|
|
|
|
prefix='edit_notification_settings_form'
|
|
|
|
)
|
2020-10-23 11:52:01 +00:00
|
|
|
|
2022-02-08 11:26:20 +00:00
|
|
|
if change_password_form.submit.data and change_password_form.validate():
|
|
|
|
current_user.password = change_password_form.new_password.data
|
2020-10-23 11:52:01 +00:00
|
|
|
db.session.commit()
|
2022-02-08 11:26:20 +00:00
|
|
|
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
|
2020-10-23 11:52:01 +00:00
|
|
|
db.session.commit()
|
2022-02-08 11:26:20 +00:00
|
|
|
flash('Your changes have been saved')
|
|
|
|
return redirect(url_for('.index'))
|
|
|
|
if (
|
|
|
|
edit_interface_settings_form.submit.data
|
|
|
|
and edit_interface_settings_form.validate()
|
|
|
|
):
|
|
|
|
current_user.setting_dark_mode = \
|
|
|
|
edit_interface_settings_form.dark_mode.data
|
|
|
|
db.session.commit()
|
|
|
|
flash('Your changes have been saved')
|
|
|
|
return redirect(url_for('.index'))
|
|
|
|
if (
|
|
|
|
edit_notification_settings_form.submit.data
|
|
|
|
and edit_notification_settings_form.validate()
|
|
|
|
):
|
|
|
|
current_user.setting_job_status_mail_notification_level = \
|
2022-02-09 15:02:37 +00:00
|
|
|
UserSettingJobStatusMailNotificationLevel[
|
2022-02-08 11:26:20 +00:00
|
|
|
edit_notification_settings_form.job_status_mail_notification_level.data # noqa
|
|
|
|
]
|
2020-10-23 11:52:01 +00:00
|
|
|
db.session.commit()
|
2022-02-08 11:26:20 +00:00
|
|
|
flash('Your changes have been saved')
|
|
|
|
return redirect(url_for('.index'))
|
|
|
|
edit_general_settings_form.email.data = current_user.email
|
|
|
|
edit_general_settings_form.username.data = current_user.username
|
|
|
|
edit_interface_settings_form.dark_mode.data = \
|
|
|
|
current_user.setting_dark_mode
|
|
|
|
edit_notification_settings_form.job_status_mail_notification_level.data = \
|
|
|
|
current_user.setting_job_status_mail_notification_level.name
|
|
|
|
return render_template(
|
|
|
|
'settings/index.html.j2',
|
|
|
|
change_password_form=change_password_form,
|
|
|
|
edit_general_settings_form=edit_general_settings_form,
|
|
|
|
edit_interface_settings_form=edit_interface_settings_form,
|
|
|
|
edit_notification_settings_form=edit_notification_settings_form,
|
|
|
|
title='Settings'
|
|
|
|
)
|
2020-10-23 11:52:01 +00:00
|
|
|
|
|
|
|
|
2021-09-13 09:45:43 +00:00
|
|
|
@bp.route('/delete')
|
2020-10-23 11:52:01 +00:00
|
|
|
@login_required
|
|
|
|
def delete():
|
|
|
|
"""
|
|
|
|
View to delete current_user and all associated data.
|
|
|
|
"""
|
|
|
|
tasks.delete_user(current_user.id)
|
|
|
|
logout_user()
|
2022-02-08 11:26:20 +00:00
|
|
|
flash('Your account has been marked for deletion')
|
2020-10-23 11:52:01 +00:00
|
|
|
return redirect(url_for('main.index'))
|