Reworking sms.py to hopefully ignore broken SMS integrations

Fixing #2
This commit is contained in:
Kumi 2021-11-12 13:38:59 +00:00
parent cb23f348f9
commit af65518b56

View file

@ -4,6 +4,10 @@ from django.conf import settings
from dbsettings.functions import getValue
import logging
logger = logging.getLogger(__name__)
providers = []
modules_available = []
@ -17,22 +21,31 @@ for module in settings.EXPEPHALON_MODULES:
modules_available.append(mos.CREATE)
except (AttributeError, ModuleNotFoundError):
continue
except Exception as e:
logger.error("Error importing SMS module {module}: {e}")
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
try:
if provider.get_name == name:
if provider.is_active or not active:
return provider
except Exception as e:
logger.error("Error checking SMS module {provider.get_name}: {e}")
def get_default_sms_provider_name():
return getValue("core.sms.default", False)
def get_default_sms_provider_name(default=False):
return getValue("core.sms.default", default)
def get_default_sms_provider():
provider = get_sms_provider_by_name(get_default_sms_provider_name(), True)
def get_default_sms_provider(active=True):
provider = get_sms_provider_by_name(get_default_sms_provider_name(), active)
if provider:
return provider
for provider in providers:
if provider.is_active:
return provider
try:
if provider.is_active or not active:
return provider
except Exception as e:
logger.error("Error checking SMS module {provider.get_name}: {e}")
raise RuntimeError("No SMS provider is currently active")
raise RuntimeError("No SMS provider is currently active")