Move settings validation out of startup.py
This also creates a new app common_initialization in order to provide a place to run initialization code common to both the LMS and CMS.
This commit is contained in:
14
openedx/core/djangoapps/common_initialization/apps.py
Normal file
14
openedx/core/djangoapps/common_initialization/apps.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Common initialization app for the LMS and CMS
|
||||
"""
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CommonInitializationConfig(AppConfig):
|
||||
name = 'openedx.core.djangoapps.common_initialization'
|
||||
verbose_name = 'Common Initialization'
|
||||
|
||||
def ready(self):
|
||||
# Common settings validations for the LMS and CMS.
|
||||
from . import checks
|
||||
49
openedx/core/djangoapps/common_initialization/checks.py
Normal file
49
openedx/core/djangoapps/common_initialization/checks.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
Common settings validations for the LMS and CMS.
|
||||
|
||||
Only populate this module with general settings validators which do not fit in
|
||||
other, more specific djangoapps. Usually, settings which are widely used
|
||||
across the entire LMS or CMS can be validated here.
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.core.checks import Error, Tags, register
|
||||
|
||||
|
||||
@register(Tags.compatibility)
|
||||
def validate_lms_root_url_setting(app_configs, **kwargs):
|
||||
"""
|
||||
Validates the LMS_ROOT_URL setting.
|
||||
"""
|
||||
errors = []
|
||||
if not getattr(settings, 'LMS_ROOT_URL', None):
|
||||
errors.append(
|
||||
Error(
|
||||
'LMS_ROOT_URL is not defined.',
|
||||
id='common.djangoapps.common_initialization.E001',
|
||||
)
|
||||
)
|
||||
return errors
|
||||
|
||||
|
||||
@register(Tags.compatibility)
|
||||
def validate_marketing_site_setting(app_configs, **kwargs):
|
||||
"""
|
||||
Validates marketing site related settings.
|
||||
"""
|
||||
errors = []
|
||||
if settings.FEATURES.get('ENABLE_MKTG_SITE'):
|
||||
if not hasattr(settings, 'MKTG_URLS'):
|
||||
errors.append(
|
||||
Error(
|
||||
'ENABLE_MKTG_SITE is True, but MKTG_URLS is not defined.',
|
||||
id='common.djangoapps.common_initialization.E002',
|
||||
)
|
||||
)
|
||||
if not settings.MKTG_URLS.get('ROOT'):
|
||||
errors.append(
|
||||
Error(
|
||||
'There is no ROOT defined in MKTG_URLS.',
|
||||
id='common.djangoapps.common_initialization.E003',
|
||||
)
|
||||
)
|
||||
return errors
|
||||
Reference in New Issue
Block a user