33 lines
No EOL
1.3 KiB
Python
33 lines
No EOL
1.3 KiB
Python
from core.classes.mail import SMTPMailProvider
|
|
|
|
import importlib
|
|
import pathlib
|
|
import os.path
|
|
import logging
|
|
|
|
from django.conf import settings
|
|
|
|
providers = { "smtp": SMTPMailProvider }
|
|
templates = {}
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
for module in settings.EXPEPHALON_MODULES + [""]:
|
|
for template in pathlib.Path(os.path.join(settings.BASE_DIR, module, "templates/mail/")).rglob("*.*"):
|
|
if os.path.isfile(template):
|
|
template_name = str(template).rsplit("templates/mail/")[-1].rsplit(".")[0]
|
|
template_format = str(template).rsplit(".")[-1].lower()
|
|
if not template_name in templates.keys():
|
|
templates[template_name] = dict()
|
|
if template_format in templates[template_name].keys() and not templates[template_name][template_format] == template:
|
|
logger.warning("Mail Template %s, that was seen at %s, was also found at %s. Using latter.",
|
|
template_name, templates[template_name][template_format], str(template))
|
|
templates[template_name][template_format] = str(template)
|
|
|
|
for module in settings.EXPEPHALON_MODULES:
|
|
try:
|
|
mom = importlib.import_module(f"{module}.mail")
|
|
for name, provider in mom.MAILPROVIDERS.items():
|
|
providers[name] = provider
|
|
except (AttributeError, ModuleNotFoundError):
|
|
continue |