expephalon/core/modules/sms.py

38 lines
1 KiB
Python
Raw Normal View History

import importlib
from django.conf import settings
from dbsettings.functions import getValue
providers = []
modules_available = []
for module in settings.EXPEPHALON_MODULES:
try:
mos = importlib.import_module(f"{module}.sms")
for provider in mos.SMSPROVIDERS:
providers.append(provider)
if mos.CREATE:
modules_available.append(mos.CREATE)
except (AttributeError, ModuleNotFoundError):
continue
def get_sms_provider_by_name(name, active=False):
for provider in providers:
if provider.get_name == name and (provider.is_active or not active):
return provider
def get_default_sms_provider_name():
return getValue("core.sms.default", False)
def get_default_sms_provider():
provider = get_sms_provider_by_name(get_default_sms_provider_name(), True)
if provider:
return provider
for provider in providers:
if provider.is_active:
return provider
raise RuntimeError("No SMS provider is currently active")