Add the ability to configure alternative domains
parent
07c789fc8b
commit
f823f1e8a5
@ -0,0 +1,9 @@
|
||||
{% extends "form.html" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Create alternative domain{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block subtitle %}
|
||||
{{ domain }}
|
||||
{% endblock %}
|
@ -0,0 +1,34 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}Alternative domain list{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block subtitle %}
|
||||
{{ domain.name }}
|
||||
{% endblock %}
|
||||
|
||||
{% block main_action %}
|
||||
<a class="btn btn-primary" href="{{ url_for('.alternative_create', domain_name=domain.name) }}">{% trans %}Add alternative{% endtrans %}</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block box %}
|
||||
<table class="table table-bordered">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{% trans %}Actions{% endtrans %}</th>
|
||||
<th>{% trans %}Name{% endtrans %}</th>
|
||||
<th>{% trans %}Created{% endtrans %}</th>
|
||||
</tr>
|
||||
{% for alternative in domain.alternatives %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ url_for('.alternative_delete', alternative=alternative.name) }}" title="{% trans %}Delete{% endtrans %}"><i class="fa fa-trash"></i></a>
|
||||
</td>
|
||||
<td>{{ alternative }}</td>
|
||||
<td>{{ alternative.created_at }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
@ -0,0 +1,46 @@
|
||||
from mailu.admin import app, db, models, forms, access
|
||||
|
||||
import flask
|
||||
import wtforms_components
|
||||
|
||||
|
||||
@app.route('/alternative/list/<domain_name>', methods=['GET'])
|
||||
@access.global_admin
|
||||
def alternative_list(domain_name):
|
||||
domain = models.Domain.query.get(domain_name) or flask.abort(404)
|
||||
return flask.render_template('alternative/list.html', domain=domain)
|
||||
|
||||
|
||||
@app.route('/alternative/create/<domain_name>', methods=['GET', 'POST'])
|
||||
@access.global_admin
|
||||
def alternative_create(domain_name):
|
||||
domain = models.Domain.query.get(domain_name) or flask.abort(404)
|
||||
form = forms.AlternativeForm()
|
||||
if form.validate_on_submit():
|
||||
conflicting_domain = models.Domain.query.get(form.name.data)
|
||||
conflicting_alternative = models.Alternative.query.get(form.name.data)
|
||||
if conflicting_domain or conflicting_alternative:
|
||||
flask.flash('Domain %s is already used' % form.name.data, 'error')
|
||||
else:
|
||||
alternative = models.Alternative(domain=domain)
|
||||
form.populate_obj(alternative)
|
||||
db.session.add(alternative)
|
||||
db.session.commit()
|
||||
flask.flash('Alternative domain %s created' % alternative)
|
||||
return flask.redirect(
|
||||
flask.url_for('.alternative_list', domain_name=domain.name))
|
||||
return flask.render_template('alternative/create.html',
|
||||
domain=domain, form=form)
|
||||
|
||||
|
||||
@app.route('/alternative/delete/<alternative>', methods=['GET', 'POST'])
|
||||
@access.global_admin
|
||||
@access.confirmation_required("delete {alternative}")
|
||||
def alternative_delete(alternative):
|
||||
alternative = models.Alternative.query.get(alternative) or flask.abort(404)
|
||||
domain = alternative.domain
|
||||
db.session.delete(alternative)
|
||||
db.session.commit()
|
||||
flask.flash('Alternative %s deleted' % alternative)
|
||||
return flask.redirect(
|
||||
flask.url_for('.alternative_list', domain_name=domain.name))
|
@ -0,0 +1,30 @@
|
||||
""" Add alternative domains
|
||||
|
||||
Revision ID: c9a0b4e653cf
|
||||
Revises: 73e56bad5ec5
|
||||
Create Date: 2017-09-03 18:23:36.356527
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'c9a0b4e653cf'
|
||||
down_revision = '73e56bad5ec5'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table('alternative',
|
||||
sa.Column('created_at', sa.Date(), nullable=False),
|
||||
sa.Column('updated_at', sa.Date(), nullable=True),
|
||||
sa.Column('comment', sa.String(length=255), nullable=True),
|
||||
sa.Column('name', sa.String(length=80), nullable=False),
|
||||
sa.Column('domain_name', sa.String(length=80), nullable=True),
|
||||
sa.ForeignKeyConstraint(['domain_name'], ['domain.name'], ),
|
||||
sa.PrimaryKeyConstraint('name')
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('alternative')
|
Loading…
Reference in New Issue