This commit is contained in:
+13
-8
@@ -4,6 +4,8 @@ import re
|
||||
from django.apps import AppConfig as _AppConfig
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from ..constants import DJANGO_MAIN_MODULE, MODULE_APP_SETTINGS_PREFIX
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -18,18 +20,21 @@ class DefaultSetting: # pylint: disable=too-few-public-methods
|
||||
self.validator = validator
|
||||
|
||||
def validate(self, value):
|
||||
if hasattr(self, 'validator') and self.validator is not None:
|
||||
if callable(self.validator):
|
||||
if not self.validator(value):
|
||||
raise ImproperlyConfigured('Validator callback {clb} returned False'.format(clb=self.validator))
|
||||
else:
|
||||
if not re.search(self.validator, value):
|
||||
raise ImproperlyConfigured('Does not match /{re}/'.format(re=self.validator))
|
||||
if self.validator is None:
|
||||
return
|
||||
if callable(self.validator):
|
||||
if not self.validator(value):
|
||||
raise ImproperlyConfigured('Validator callback {clb} returned False'.format(clb=self.validator))
|
||||
else:
|
||||
if not re.search(self.validator, value):
|
||||
raise ImproperlyConfigured('Does not match /{re}/'.format(re=self.validator))
|
||||
|
||||
|
||||
class AppSettings: # pylint: disable=too-few-public-methods
|
||||
def __init__(self, app_name, defaults):
|
||||
settings_name = 'main.settings-' + app_name
|
||||
settings_name = '{main_module}.{prefix}{app_name}'.format(main_module=DJANGO_MAIN_MODULE,
|
||||
prefix=MODULE_APP_SETTINGS_PREFIX,
|
||||
app_name=app_name)
|
||||
|
||||
try:
|
||||
settings_module = importlib.import_module(settings_name)
|
||||
|
||||
Reference in New Issue
Block a user