mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-10 03:11:07 +00:00
Add django constance to thirdpart to void dependency
This commit is contained in:
30
thirdpart/constance/base.py
Normal file
30
thirdpart/constance/base.py
Normal file
@@ -0,0 +1,30 @@
|
||||
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()
|
Reference in New Issue
Block a user