2020-04-13 10:08:59 +00:00
|
|
|
import importlib
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
2020-04-13 18:03:01 +00:00
|
|
|
from dbsettings.functions import getValue
|
2020-04-13 10:08:59 +00:00
|
|
|
|
|
|
|
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:
|
2020-04-13 18:03:01 +00:00
|
|
|
modules_available.append(mos.CREATE)
|
2020-04-13 10:08:59 +00:00
|
|
|
except (AttributeError, ModuleNotFoundError):
|
|
|
|
continue
|
|
|
|
|
2020-05-23 09:12:48 +00:00
|
|
|
def get_sms_provider_by_name(name, active=False):
|
2020-04-13 10:08:59 +00:00
|
|
|
for provider in providers:
|
2020-05-23 09:12:48 +00:00
|
|
|
if provider.get_name == name and (provider.is_active or not active):
|
2020-04-13 10:08:59 +00:00
|
|
|
return provider
|
|
|
|
|
|
|
|
def get_default_sms_provider_name():
|
|
|
|
return getValue("core.sms.default", False)
|
|
|
|
|
|
|
|
def get_default_sms_provider():
|
2020-05-23 09:12:48 +00:00
|
|
|
provider = get_sms_provider_by_name(get_default_sms_provider_name(), True)
|
|
|
|
if provider:
|
|
|
|
return provider
|
|
|
|
|
2020-04-13 10:08:59 +00:00
|
|
|
for provider in providers:
|
|
|
|
if provider.is_active:
|
2020-05-23 09:12:48 +00:00
|
|
|
return provider
|
|
|
|
|
|
|
|
raise RuntimeError("No SMS provider is currently active")
|