From 011e1fa52d1d68011e67591a835c8e01345a3c5e Mon Sep 17 00:00:00 2001 From: kaiyou Date: Fri, 10 Nov 2017 15:25:30 +0100 Subject: [PATCH] Add an end of vacation field, related to #218 --- core/admin/mailu/models.py | 4 +++- core/admin/mailu/ui/forms.py | 1 + core/admin/mailu/ui/templates/user/reply.html | 6 +++-- .../migrations/versions/77aa22ad72e2_.py | 23 +++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 core/admin/migrations/versions/77aa22ad72e2_.py diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index 65ba1ef8..901054a8 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -2,7 +2,7 @@ from mailu import app, db, dkim, login_manager from sqlalchemy.ext import declarative from passlib import context, hash -from datetime import datetime +from datetime import datetime, date from email.mime import text @@ -194,6 +194,8 @@ class User(Base, Email): reply_enabled = db.Column(db.Boolean(), nullable=False, default=False) reply_subject = db.Column(db.String(255), nullable=True, default=None) reply_body = db.Column(db.Text(), nullable=True, default=None) + reply_enddate = db.Column(db.Date, nullable=False, + default=date(2999, 12, 31)) # Settings displayed_name = db.Column(db.String(160), nullable=False, default="") diff --git a/core/admin/mailu/ui/forms.py b/core/admin/mailu/ui/forms.py index 793057fc..451db811 100644 --- a/core/admin/mailu/ui/forms.py +++ b/core/admin/mailu/ui/forms.py @@ -101,6 +101,7 @@ class UserReplyForm(flask_wtf.FlaskForm): reply_subject = fields.StringField(_('Reply subject')) reply_body = fields.StringField(_('Reply body'), widget=widgets.TextArea()) + reply_enddate = fields.html5.DateField(_('End of vacation')) submit = fields.SubmitField(_('Update')) diff --git a/core/admin/mailu/ui/templates/user/reply.html b/core/admin/mailu/ui/templates/user/reply.html index fcea28d3..7906bc42 100644 --- a/core/admin/mailu/ui/templates/user/reply.html +++ b/core/admin/mailu/ui/templates/user/reply.html @@ -13,12 +13,14 @@
{{ form.hidden_tag() }} {{ macros.form_field(form.reply_enabled, - onchange="if(this.checked){$('#reply_subject,#reply_body').removeAttr('readonly')} - else{$('#reply_subject,#reply_body').attr('readonly', '')}") }} + onchange="if(this.checked){$('#reply_subject,#reply_body,#reply_enddate').removeAttr('readonly')} + else{$('#reply_subject,#reply_body,#reply_enddate').attr('readonly', '')}") }} {{ macros.form_field(form.reply_subject, **{("rw" if user.reply_enabled else "readonly"): ""}) }} {{ macros.form_field(form.reply_body, rows=10, **{("rw" if user.reply_enabled else "readonly"): ""}) }} + {{ macros.form_field(form.reply_enddate, + **{("rw" if user.reply_enabled else "readonly"): ""}) }} {{ macros.form_field(form.submit) }}
{% endcall %} diff --git a/core/admin/migrations/versions/77aa22ad72e2_.py b/core/admin/migrations/versions/77aa22ad72e2_.py new file mode 100644 index 00000000..97601ac1 --- /dev/null +++ b/core/admin/migrations/versions/77aa22ad72e2_.py @@ -0,0 +1,23 @@ +""" Add an enddate for the vacation mode + +Revision ID: 77aa22ad72e2 +Revises: 9400a032eb1a +Create Date: 2017-11-10 15:10:33.477592 + +""" + +# revision identifiers, used by Alembic. +revision = '77aa22ad72e2' +down_revision = '9400a032eb1a' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('user', sa.Column('reply_enddate', sa.Date(), nullable=False, + server_default="2999-12-31")) + + +def downgrade(): + op.drop_column('user', 'reply_enddate')