Current implementation of MultiTemplateConnectionConfig is a bit rigid. Template folders are defined statically via get_all_templates() and TEMPLATE_FOLDER is not used.
It would be great to make this more flexible:
allow passing template folders dynamically (not only at class level)
either remove or properly use TEMPLATE_FOLDER
make it easier to extend/override templates per environment or use case
class MultiTemplateConnectionConfig(ConnectionConfig):
TEMPLATE_FOLDERS: list[Path] = get_all_templates()
# fastapi mail stub
TEMPLATE_FOLDER: Path = Path()
def template_engine(self) -> Environment:
loader = FileSystemLoader(self.TEMPLATE_FOLDERS)
return Environment(loader=loader)
class Mailer:
def __init__(self) -> None:
self.conf = MultiTemplateConnectionConfig(
MAIL_USERNAME=settings.mail.username,
MAIL_PASSWORD=settings.mail.password,
MAIL_FROM=settings.mail.from_email,
MAIL_PORT=settings.mail.port,
MAIL_SERVER=settings.mail.server,
MAIL_STARTTLS=settings.mail.mail_starttls,
MAIL_SSL_TLS=settings.mail.mail_ssl_tls,
USE_CREDENTIALS=settings.mail.use_credentials,
VALIDATE_CERTS=settings.mail.validate_certs,
)
self.fast_mail = FastMail(self.conf)
Current implementation of MultiTemplateConnectionConfig is a bit rigid. Template folders are defined statically via get_all_templates() and TEMPLATE_FOLDER is not used.
It would be great to make this more flexible:
allow passing template folders dynamically (not only at class level)
either remove or properly use TEMPLATE_FOLDER
make it easier to extend/override templates per environment or use case