Remove darkmode setting

This commit is contained in:
Patrick Jentsch 2022-11-17 10:52:46 +01:00
parent e92624f0c0
commit bbea1553b8
9 changed files with 27 additions and 110 deletions

View File

@ -6,7 +6,6 @@ from app.decorators import admin_required
from app.models import Role, User, UserSettingJobStatusMailNotificationLevel
from app.settings.forms import (
EditGeneralSettingsForm,
EditInterfaceSettingsForm,
EditNotificationSettingsForm
)
from . import bp
@ -55,9 +54,6 @@ def edit_user(user_id):
user,
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'
)
@ -76,12 +72,6 @@ def edit_user(user_id):
db.session.commit()
flash('Your changes have been saved')
return redirect(url_for('.edit_user', user_id=user.id))
if (edit_interface_settings_form.submit.data
and edit_interface_settings_form.validate()):
user.setting_dark_mode = edit_interface_settings_form.dark_mode.data
db.session.commit()
flash('Your changes have been saved')
return redirect(url_for('.edit_user', user_id=user.id))
if (edit_notification_settings_form.submit.data
and edit_notification_settings_form.validate()):
user.setting_job_status_mail_notification_level = \
@ -93,13 +83,11 @@ def edit_user(user_id):
return redirect(url_for('.edit_user', user_id=user.id))
admin_edit_user_form.prefill(user)
edit_general_settings_form.prefill(user)
edit_interface_settings_form.prefill(user)
edit_notification_settings_form.prefill(user)
return render_template(
'admin/edit_user.html.j2',
admin_edit_user_form=admin_edit_user_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='Edit user',
user=user

View File

@ -150,7 +150,6 @@ class UserSchema(ma.SQLAlchemySchema):
last_seen = ma.auto_field(dump_only=True)
password = ma.String(load_only=True)
last_seen = ma.auto_field(dump_only=True)
setting_dark_mode = ma.auto_field()
setting_job_status_mail_notification_level = ma.String(
validate=validate.OneOf(list(UserSettingJobStatusMailNotificationLevel.__members__.keys()))
)

View File

@ -263,7 +263,6 @@ class User(HashidMixin, UserMixin, db.Model):
password_hash = db.Column(db.String(128))
confirmed = db.Column(db.Boolean, default=False)
member_since = db.Column(db.DateTime(), default=datetime.utcnow)
setting_dark_mode = db.Column(db.Boolean, default=False)
setting_job_status_mail_notification_level = db.Column(
IntEnumColumn(UserSettingJobStatusMailNotificationLevel),
default=UserSettingJobStatusMailNotificationLevel.END
@ -500,7 +499,6 @@ class User(HashidMixin, UserMixin, db.Model):
'member_since': f'{self.member_since.isoformat()}Z',
'username': self.username,
'settings': {
'dark_mode': self.setting_dark_mode,
'job_status_mail_notification_level': \
self.setting_job_status_mail_notification_level.name
}

View File

@ -71,10 +71,6 @@ class EditGeneralSettingsForm(FlaskForm):
super().__init__(*args, **kwargs)
self.user = user
def prefill(self, user):
self.email.data = user.email
self.username.data = user.username
def validate_email(self, field):
if (field.data != self.user.email
and User.query.filter_by(email=field.data).first()):
@ -86,13 +82,6 @@ class EditGeneralSettingsForm(FlaskForm):
raise ValidationError('Username already in use')
class EditInterfaceSettingsForm(FlaskForm):
dark_mode = BooleanField('Dark mode')
submit = SubmitField()
def prefill(self, user):
self.dark_mode.data = user.setting_dark_mode
class EditNotificationSettingsForm(FlaskForm):
job_status_mail_notification_level = SelectField(
'Job status mail notification level',

View File

@ -6,7 +6,6 @@ from . import bp
from .forms import (
ChangePasswordForm,
EditGeneralSettingsForm,
EditInterfaceSettingsForm,
EditNotificationSettingsForm
)
@ -20,11 +19,9 @@ def settings():
)
edit_general_settings_form = EditGeneralSettingsForm(
current_user,
obj=current_user,
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'
)
@ -41,13 +38,6 @@ def settings():
db.session.commit()
flash('Your changes have been saved')
return redirect(url_for('.settings'))
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('.settings'))
if (edit_notification_settings_form.submit.data
and edit_notification_settings_form.validate()):
current_user.setting_job_status_mail_notification_level = (
@ -58,14 +48,11 @@ def settings():
db.session.commit()
flash('Your changes have been saved')
return redirect(url_for('.settings'))
edit_general_settings_form.prefill(current_user)
edit_interface_settings_form.prefill(current_user)
edit_notification_settings_form.prefill(current_user)
return render_template(
'settings/settings.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'
)

View File

@ -27,38 +27,6 @@
</div>
</form>
<form method="POST">
{{ edit_interface_settings_form.hidden_tag() }}
<div class="card">
<div class="card-content">
<span class="card-title">Interface settings</span>
<div class="row">
<div class="col s12"><p>&nbsp;</p></div>
<div class="col s1">
<p><i class="material-icons">brightness_3</i></p>
</div>
<div class="col s8">
<p>{{ edit_interface_settings_form.dark_mode.label.text }}</p>
<p class="light">Enable dark mode to ease your eyes.</p>
</div>
<div class="col s3 right-align">
<div class="switch">
<label>
{{ edit_interface_settings_form.dark_mode() }}
<span class="lever"></span>
</label>
</div>
</div>
</div>
</div>
<div class="card-action">
<div class="right-align">
{{ wtf.render_field(edit_interface_settings_form.submit, material_icon='send') }}
</div>
</div>
</div>
</form>
<form method="POST">
{{ edit_notification_settings_form.hidden_tag() }}
<div class="card">

View File

@ -5,12 +5,6 @@
{% block head %}
{{ super() }}
<link href="{{ url_for('static', filename='images/nopaque_-_favicon.png') }}" rel="icon">
{% if current_user.setting_dark_mode %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/darkreader/4.9.40/darkreader.min.js" integrity="sha512-0Jbi9gWSyU5SvNS16za0aILl6l+MgM8N+TGlZxy4qPQEzqKoU9egh4h56Kz0xp2R+ZFPQMfeDn26Gh6cqu2WAg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
DarkReader.enable();
</script>
{% endif %}
{% endblock head %}
{% block metas %}

View File

@ -27,38 +27,6 @@
</div>
</form>
<form method="POST">
{{ edit_interface_settings_form.hidden_tag() }}
<div class="card">
<div class="card-content">
<span class="card-title">Interface settings</span>
<div class="row">
<div class="col s12"><p>&nbsp;</p></div>
<div class="col s1">
<p><i class="material-icons">brightness_3</i></p>
</div>
<div class="col s8">
<p>{{ edit_interface_settings_form.dark_mode.label.text }}</p>
<p class="light">Enable dark mode to ease your eyes.</p>
</div>
<div class="col s3 right-align">
<div class="switch">
<label>
{{ edit_interface_settings_form.dark_mode() }}
<span class="lever"></span>
</label>
</div>
</div>
</div>
</div>
<div class="card-action">
<div class="right-align">
{{ wtf.render_field(edit_interface_settings_form.submit, material_icon='send') }}
</div>
</div>
</div>
</form>
<form method="POST">
{{ edit_notification_settings_form.hidden_tag() }}
<div class="card">

View File

@ -0,0 +1,26 @@
"""Remove setting_dark_mode column from users table
Revision ID: 89e9526089bf
Revises: 721829b5dd25
Create Date: 2022-11-17 09:47:27.724692
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '89e9526089bf'
down_revision = '721829b5dd25'
branch_labels = None
depends_on = None
def upgrade():
op.drop_column('users', 'setting_dark_mode')
def downgrade():
op.add_column('users',
sa.Column('setting_dark_mode', sa.Boolean(), nullable=True)
)