From a9cb1e2d116b304b98e3fb5639d33d96d693a13f Mon Sep 17 00:00:00 2001 From: Pierre Jaury Date: Tue, 8 Nov 2016 20:33:01 +0100 Subject: [PATCH] Change the spam threshold to an integer, related to #103 --- admin/mailu/admin/models.py | 2 +- .../mailu/admin/templates/user/settings.html | 2 +- admin/migrations/versions/12e9a4f6ed73_.py | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 admin/migrations/versions/12e9a4f6ed73_.py diff --git a/admin/mailu/admin/models.py b/admin/mailu/admin/models.py index 18d03a26..d7d46e65 100644 --- a/admin/mailu/admin/models.py +++ b/admin/mailu/admin/models.py @@ -152,7 +152,7 @@ class User(Base, Email): # Settings displayed_name = db.Column(db.String(160), nullable=False, default="") spam_enabled = db.Column(db.Boolean(), nullable=False, default=True) - spam_threshold = db.Column(db.Numeric(), nullable=False, default=80.0) + spam_threshold = db.Column(db.Integer(), nullable=False, default=80.0) # Flask-login attributes is_authenticated = True diff --git a/admin/mailu/admin/templates/user/settings.html b/admin/mailu/admin/templates/user/settings.html index ede0b608..3a36df1e 100644 --- a/admin/mailu/admin/templates/user/settings.html +++ b/admin/mailu/admin/templates/user/settings.html @@ -14,7 +14,7 @@ User settings {{ macros.form_field(form.displayed_name) }} {{ macros.form_field(form.spam_enabled) }} {{ macros.form_field(form.spam_threshold, step=1, max=100, - prepend=''+(form.spam_threshold.data).__int__().__str__()+' / 100', + prepend=''+form.spam_threshold.data.__str__()+' / 100', oninput='$("#threshold").text(this.value);') }} {{ macros.form_field(form.submit) }} diff --git a/admin/migrations/versions/12e9a4f6ed73_.py b/admin/migrations/versions/12e9a4f6ed73_.py new file mode 100644 index 00000000..35b49941 --- /dev/null +++ b/admin/migrations/versions/12e9a4f6ed73_.py @@ -0,0 +1,35 @@ +"""Set the spam threshold as an integer + +Revision ID: 12e9a4f6ed73 +Revises: 27ae2f102682 +Create Date: 2016-11-08 20:22:54.169833 + +""" + +# revision identifiers, used by Alembic. +revision = '12e9a4f6ed73' +down_revision = '27ae2f102682' + +from alembic import op +import sqlalchemy as sa + +from mailu.admin import models +from mailu import db + + +def upgrade(): + # Make sure that every value is already an Integer + for user in models.User.query.all(): + user.spam_threshold = int(user.spam_threshold) + db.session.commit() + # Migrate the table + with op.batch_alter_table('user') as batch: + batch.alter_column( + 'spam_threshold', existing_type=db.Numeric(), type_=db.Integer()) + + +def downgrade(): + # Migrate the table + with op.batch_alter_table('user') as batch: + batch.alter_column( + 'spam_threshold', existing_type=db.Integer(), type_=db.Numeric())