app-MAIL-temp/app/dashboard/views/refused_email.py

40 lines
1.2 KiB
Python
Raw Normal View History

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:
2021-09-08 11:29:55 +02:00
LOG.w("Cannot parse highlight_id %s", highlight_id)
2020-09-14 19:54:00 +02:00
highlight_id = None
2020-03-14 16:10:09 +01:00
2020-08-27 10:20:48 +02:00
email_logs: [EmailLog] = (
EmailLog.filter(
2020-12-06 22:03:06 +01:00
EmailLog.user_id == current_user.id, EmailLog.refused_email_id.isnot(None)
2020-08-27 10:20:48 +02:00
)
.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())