2020-11-13 09:01:51 +00:00
|
|
|
from flask import flash, redirect, render_template, url_for
|
2022-09-02 11:07:30 +00:00
|
|
|
from flask_login import current_user, login_required
|
|
|
|
from app import db
|
|
|
|
from app.models import UserSettingJobStatusMailNotificationLevel
|
|
|
|
from . import bp
|
2022-02-08 11:26:20 +00:00
|
|
|
from .forms import (
|
|
|
|
ChangePasswordForm,
|
|
|
|
EditGeneralSettingsForm,
|
2022-11-29 15:46:33 +00:00
|
|
|
EditNotificationSettingsForm,
|
|
|
|
EditPrivacySettingsForm
|
2022-02-08 11:26:20 +00:00
|
|
|
)
|
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
|
2022-09-02 11:07:30 +00:00
|
|
|
def settings():
|
2022-02-08 11:26:20 +00:00
|
|
|
change_password_form = ChangePasswordForm(
|
2022-09-02 11:07:30 +00:00
|
|
|
current_user,
|
|
|
|
prefix='change-password-form'
|
2022-02-08 11:26:20 +00:00
|
|
|
)
|
|
|
|
edit_general_settings_form = EditGeneralSettingsForm(
|
2022-09-02 11:07:30 +00:00
|
|
|
current_user,
|
2022-11-24 11:24:29 +00:00
|
|
|
data=current_user.to_json_serializeable(),
|
2022-09-02 11:07:30 +00:00
|
|
|
prefix='edit-general-settings-form'
|
2022-02-08 11:26:20 +00:00
|
|
|
)
|
|
|
|
edit_notification_settings_form = EditNotificationSettingsForm(
|
2022-11-24 11:24:29 +00:00
|
|
|
data=current_user.to_json_serializeable(),
|
2022-09-02 11:07:30 +00:00
|
|
|
prefix='edit-notification-settings-form'
|
2022-02-08 11:26:20 +00:00
|
|
|
)
|
2022-11-29 15:46:33 +00:00
|
|
|
edit_privacy_settings_form = EditPrivacySettingsForm(
|
|
|
|
data=current_user.to_json_serializeable(),
|
|
|
|
prefix='edit-privacy-settings-form'
|
|
|
|
)
|
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'))
|
2022-09-02 11:07:30 +00:00
|
|
|
if (edit_general_settings_form.submit.data
|
|
|
|
and edit_general_settings_form.validate()):
|
2022-02-08 11:26:20 +00:00
|
|
|
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')
|
2022-09-02 11:07:30 +00:00
|
|
|
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 = (
|
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
|
|
|
|
]
|
2022-09-02 11:07:30 +00:00
|
|
|
)
|
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')
|
2022-09-02 11:07:30 +00:00
|
|
|
return redirect(url_for('.settings'))
|
2022-11-29 15:46:33 +00:00
|
|
|
user_image = 'static/images/user_avatar.png'
|
2022-02-08 11:26:20 +00:00
|
|
|
return render_template(
|
2022-09-02 11:07:30 +00:00
|
|
|
'settings/settings.html.j2',
|
2022-02-08 11:26:20 +00:00
|
|
|
change_password_form=change_password_form,
|
|
|
|
edit_general_settings_form=edit_general_settings_form,
|
|
|
|
edit_notification_settings_form=edit_notification_settings_form,
|
2022-11-29 15:46:33 +00:00
|
|
|
edit_privacy_settings_form=edit_privacy_settings_form,
|
|
|
|
user_image=user_image,
|
|
|
|
title='Profile & Settings'
|
2022-02-08 11:26:20 +00:00
|
|
|
)
|