Reformat django settings export
This commit is contained in:
parent
68448c5926
commit
b8f5d5a1cc
|
@ -7,13 +7,10 @@ https://github.com/jakubroztocil/django-settings-export
|
|||
from django.conf import settings as django_settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
|
||||
__version__ = '1.2.1'
|
||||
__version__ = "1.2.1"
|
||||
|
||||
|
||||
VARIABLE_NAME = getattr(django_settings,
|
||||
'SETTINGS_EXPORT_VARIABLE_NAME',
|
||||
'settings')
|
||||
VARIABLE_NAME = getattr(django_settings, "SETTINGS_EXPORT_VARIABLE_NAME", "settings")
|
||||
|
||||
|
||||
class SettingsExportError(ImproperlyConfigured):
|
||||
|
@ -35,16 +32,13 @@ def settings_export(request):
|
|||
set, the context variable will be `settings`.
|
||||
|
||||
"""
|
||||
variable_name = getattr(django_settings,
|
||||
'SETTINGS_EXPORT_VARIABLE_NAME',
|
||||
'settings')
|
||||
return {
|
||||
variable_name: _get_exported_settings()
|
||||
}
|
||||
variable_name = getattr(
|
||||
django_settings, "SETTINGS_EXPORT_VARIABLE_NAME", "settings"
|
||||
)
|
||||
return {variable_name: _get_exported_settings()}
|
||||
|
||||
|
||||
class ExportedSettings(dict):
|
||||
|
||||
def __getitem__(self, item):
|
||||
"""Fail loudly if accessing a setting that is not exported."""
|
||||
try:
|
||||
|
@ -55,24 +49,21 @@ class ExportedSettings(dict):
|
|||
# can access the existing attribute (e.g. `items()`).
|
||||
raise
|
||||
raise UnexportedSettingError(
|
||||
'The `{key}` setting key is not accessible'
|
||||
"The `{key}` setting key is not accessible"
|
||||
' from templates: add "{key}" to'
|
||||
' `settings.SETTINGS_EXPORT` to change that.'
|
||||
.format(key=item)
|
||||
" `settings.SETTINGS_EXPORT` to change that.".format(key=item)
|
||||
)
|
||||
|
||||
|
||||
def _get_exported_settings():
|
||||
exported_settings = ExportedSettings()
|
||||
for key in getattr(django_settings, 'SETTINGS_EXPORT', []):
|
||||
for key in getattr(django_settings, "SETTINGS_EXPORT", []):
|
||||
try:
|
||||
value = getattr(django_settings, key)
|
||||
except AttributeError:
|
||||
raise UndefinedSettingError(
|
||||
'"settings.%s" is included in settings.SETTINGS_EXPORT '
|
||||
'but it does not exist. '
|
||||
% key
|
||||
"but it does not exist. " % key
|
||||
)
|
||||
exported_settings[key] = value
|
||||
return exported_settings
|
||||
|
||||
|
|
Loading…
Reference in New Issue