From 684a2624e332b43dfc26e73e201c256d70ef0654 Mon Sep 17 00:00:00 2001 From: plup <plup@plup.io> Date: Sun, 5 Apr 2020 21:48:06 +0200 Subject: [PATCH] feature: patched django.conf.settings with crafted object --- djangoldp/conf/settings.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/djangoldp/conf/settings.py b/djangoldp/conf/settings.py index 408810ac..65adf99b 100644 --- a/djangoldp/conf/settings.py +++ b/djangoldp/conf/settings.py @@ -1,5 +1,7 @@ -import yaml import os +import sys +import yaml +from django import conf from django.conf import global_settings try: @@ -7,6 +9,8 @@ try: except ImportError: from django.utils.importlib import import_module +# Reference: https://github.com/django/django/blob/master/django/conf/__init__.py + def configure(): @@ -15,16 +19,21 @@ def configure(): if not settings: raise ImportError('Settings could not be imported because DJANGOLDP_SETTINGS is not set') - #mod = import_module(settings) - - # craft a settings module from class + # patch django.conf.settings + # Inspiration: https://github.com/rochacbruno/dynaconf/blob/master/dynaconf/contrib/django_dynaconf_v2.py ldpsettings = LDPSettings('config.yml') - for key in dir(ldpsettings): - if key.isupper(): - print(getattr(ldpsettings, key)) + class Wrapper(object): + + def __getattribute__(self, name): + if name == "settings": + return ldpsettings + else: + return getattr(conf, name) + + sys.modules["django.conf"] = Wrapper() # setup vars to resume django setup process - os.environ['DJANGO_SETTINGS_MODULE'] = settings + #os.environ['DJANGO_SETTINGS_MODULE'] = settings # build a class from django default settings -- GitLab