2020-03-14 16:10:09 +01:00
|
|
|
from flask import render_template, request
|
2020-03-20 11:39:45 +01:00
|
|
|
from flask_login import login_required, current_user
|
2020-03-14 16:10:09 +01:00
|
|
|
|
|
|
|
from app.dashboard.base import dashboard_bp
|
2020-09-14 19:54:00 +02:00
|
|
|
from app.log import LOG
|
2020-03-17 11:10:50 +01:00
|
|
|
from app.models import EmailLog
|
2020-03-14 16:10:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
@dashboard_bp.route("/refused_email", methods=["GET", "POST"])
|
|
|
|
@login_required
|
|
|
|
def refused_email_route():
|
|
|
|
# Highlight a refused email
|
2020-03-30 21:46:52 +02:00
|
|
|
highlight_id = request.args.get("highlight_id")
|
|
|
|
if highlight_id:
|
2020-09-14 19:54:00 +02:00
|
|
|
try:
|
|
|
|
highlight_id = int(highlight_id)
|
|
|
|
except ValueError:
|
|
|
|
LOG.warning("Cannot parse highlight_id %s", highlight_id)
|
|
|
|
highlight_id = None
|
2020-03-14 16:10:09 +01:00
|
|
|
|
2020-08-27 10:20:48 +02:00
|
|
|
email_logs: [EmailLog] = (
|
|
|
|
EmailLog.query.filter(
|
|
|
|
EmailLog.user_id == current_user.id, EmailLog.refused_email_id != None
|
|
|
|
)
|
|
|
|
.order_by(EmailLog.id.desc())
|
|
|
|
.all()
|
|
|
|
)
|
2020-03-14 16:10:09 +01:00
|
|
|
|
2020-04-04 19:21:31 +02:00
|
|
|
# make sure the highlighted email_log is the first email_log
|
2020-03-14 16:10:09 +01:00
|
|
|
highlight_index = None
|
2020-04-04 19:21:31 +02:00
|
|
|
for ix, email_log in enumerate(email_logs):
|
|
|
|
if email_log.id == highlight_id:
|
2020-03-14 16:10:09 +01:00
|
|
|
highlight_index = ix
|
|
|
|
break
|
|
|
|
|
|
|
|
if highlight_index:
|
2020-03-30 21:46:52 +02:00
|
|
|
email_logs.insert(0, email_logs.pop(highlight_index))
|
2020-03-14 16:10:09 +01:00
|
|
|
|
|
|
|
return render_template("dashboard/refused_email.html", **locals())
|