django-constance/constance/base.py
Jannis Leidel 69221ba2b4 Renamed config module to base to prevent ambiguity
This should fix #80 that is triggered by Django's new strickter import time loading process.
2014-11-21 20:16:39 +01:00

30 lines
824 B
Python

from . import settings, utils
class Config(object):
"""
The global config wrapper that handles the backend.
"""
def __init__(self):
super(Config, self).__setattr__('_backend',
utils.import_module_attr(settings.BACKEND)())
def __getattr__(self, key):
try:
default, help_text = settings.CONFIG[key]
except KeyError:
raise AttributeError(key)
result = self._backend.get(key)
if result is None:
result = default
setattr(self, key, default)
return result
return result
def __setattr__(self, key, value):
if key not in settings.CONFIG:
raise AttributeError(key)
self._backend.set(key, value)
def __dir__(self):
return settings.CONFIG.keys()