Improve how settings are loaded from config file

Update the way settings are loaded. Instead of loading the
entire config file now settings are loaded from the config
file on demand when the cache misses.

Improve the smart settings classes tests and add another test
for the config file loading.

Add support for variable config file path.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2018-12-15 21:00:51 -04:00
parent 8559565dca
commit b83ab1b528
7 changed files with 67 additions and 26 deletions
+9 -1
View File
@@ -13,6 +13,8 @@ from django.conf import settings
from django.utils.functional import Promise
from django.utils.encoding import force_text, python_2_unicode_compatible
from .utils import read_configuration_file
logger = logging.getLogger(__name__)
@@ -173,7 +175,13 @@ class Setting(object):
)
)
else:
self.raw_value = getattr(settings, self.global_name, self.default)
self.raw_value = read_configuration_file(
path=settings.CONFIGURATION_FILEPATH
).get(
self.global_name, getattr(
settings, self.global_name, self.default
)
)
self.yaml = Setting.serialize_value(self.raw_value)
self.loaded = True