Skip to content
Snippets Groups Projects
Commit 5a0d681f authored by plup's avatar plup
Browse files

fix: reworked the parameter fetching in packages

parent 176fdcae
No related branches found
No related tags found
1 merge request!158Load djangoldp conguration from YAML file
...@@ -37,7 +37,7 @@ ALLOWED_HOSTS = [] ...@@ -37,7 +37,7 @@ ALLOWED_HOSTS = []
TIME_ZONE = 'America/Chicago' TIME_ZONE = 'America/Chicago'
# If you set this to True, Django will use timezone-aware datetimes. # If you set this to True, Django will use timezone-aware datetimes.
USE_TZ = False USE_TZ = True
# Language code for this installation. All choices can be found here: # Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html # http://www.i18nguy.com/unicode/language-identifiers.html
......
...@@ -52,28 +52,36 @@ class LDPSettings(object): ...@@ -52,28 +52,36 @@ class LDPSettings(object):
"""Set a dict has current configuration.""" """Set a dict has current configuration."""
self._config = value self._config = value
def register(self, _list, name): def fetch(self, attributes):
""" """
Explore packages looking for a list of params to register within the server configuration. Explore packages looking for a list of attributes within the server configuration.
It extends it with found elements and doesn't manage duplications or collisions. It returns all elements found and doesn't manage duplications or collisions.
All elements are returned.
""" """
attr = []
for pkg in self.DJANGOLDP_PACKAGES: for pkg in self.DJANGOLDP_PACKAGES:
try: try:
# import from an installed package # import from an installed package
mod = import_module(f'{pkg}.djangoldp_settings') mod = import_module(f'{pkg}.djangoldp_settings')
_list.extend(getattr(mod, name)) logger.debug(f'Settings found for {pkg} in a installed package')
logger.debug(f'{name} found in installed package {pkg}') except (ModuleNotFoundError):
except (ModuleNotFoundError, NameError):
try: try:
# import from a local packages in a subfolder (same name the template is built this way) # import from a local packages in a subfolder (same name the template is built this way)
mod = import_module(f'{pkg}.{pkg}.djangoldp_settings') mod = import_module(f'{pkg}.{pkg}.djangoldp_settings')
_list.extend(getattr(mod, name)) logger.debug(f'Settings found for {pkg} in a local package')
logger.debug(f'{name} found in local package {pkg}') except (ModuleNotFoundError):
except (ModuleNotFoundError, NameError): logger.debug(f'No settings found for {pkg}')
logger.info(f'No {name} found for package {pkg}') break
pass
# looking for the attribute list in the module
try:
attr.extend(getattr(mod, attributes))
logger.debug(f'{attributes} found in local package {pkg}')
except (NameError):
logger.info(f'No {attributes} found for package {pkg}')
pass
return attr
@property @property
def DJANGOLDP_PACKAGES(self): def DJANGOLDP_PACKAGES(self):
...@@ -95,7 +103,7 @@ class LDPSettings(object): ...@@ -95,7 +103,7 @@ class LDPSettings(object):
apps.extend(self.DJANGOLDP_PACKAGES) apps.extend(self.DJANGOLDP_PACKAGES)
# add apps referenced in packages # add apps referenced in packages
self.register(apps, 'INSTALLED_APPS') apps.extend(self.fetch('INSTALLED_APPS'))
return apps return apps
...@@ -110,7 +118,7 @@ class LDPSettings(object): ...@@ -110,7 +118,7 @@ class LDPSettings(object):
middlewares = getattr(global_settings, 'MIDDLEWARE') middlewares = getattr(global_settings, 'MIDDLEWARE')
# explore packages looking for middleware to reference # explore packages looking for middleware to reference
self.register(middlewares, 'MIDDLEWARE') middlewares.extend(self.fetch('MIDDLEWARE'))
return middlewares return middlewares
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment