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

31 lines
939 B
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-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
highlight_fel_id = request.args.get("highlight_fel_id")
if highlight_fel_id:
highlight_fel_id = int(highlight_fel_id)
2020-03-20 11:39:45 +01:00
fels: [EmailLog] = EmailLog.query.filter(
EmailLog.user_id == current_user.id, EmailLog.refused_email_id != None
).all()
2020-03-14 16:10:09 +01:00
# make sure the highlighted fel is the first fel
highlight_index = None
for ix, fel in enumerate(fels):
if fel.id == highlight_fel_id:
highlight_index = ix
break
if highlight_index:
fels.insert(0, fels.pop(highlight_index))
return render_template("dashboard/refused_email.html", **locals())