mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-07-05 20:23:17 +00:00
Restructure imports (3rd party imports first)
This commit is contained in:
16
app/email.py
16
app/email.py
@ -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
|
||||
|
Reference in New Issue
Block a user