Restructure imports (3rd party imports first)

This commit is contained in:
Patrick Jentsch
2022-09-02 13:02:04 +02:00
parent 8f03c2aea7
commit ec9225b881
12 changed files with 29 additions and 40 deletions

View File

@ -1,11 +1,10 @@
from app import mail
from flask import current_app, Flask, render_template
from flask import current_app, render_template
from flask_mail import Message
from threading import Thread
from typing import Any
from app import mail
def create_message(recipient: str, subject: str, template: str, **kwargs: Any) -> Message:
def create_message(recipient, subject, template, **kwargs):
subject_prefix: str = current_app.config['NOPAQUE_MAIL_SUBJECT_PREFIX']
msg: Message = Message(
body=render_template(f'{template}.txt.j2', **kwargs),
@ -16,12 +15,11 @@ def create_message(recipient: str, subject: str, template: str, **kwargs: Any) -
return msg
def _send(app: Flask, msg):
with app.app_context():
mail.send(msg)
def send(msg, *args, **kwargs):
def _send(app, msg):
with app.app_context():
mail.send(msg)
def send(msg: Message, *args, **kwargs):
thread = Thread(target=_send, args=[current_app._get_current_object(), msg])
thread.start()
return thread