django-constance/constance/utils.py
Søren Howe Gersager 0047a781af
Fix constance management command without admin installed (#506)
* refactor out ConstanceForm and get_values into forms.py and utils.py respectively

* fix tests and documentation

* correct mock import

* fix merge
2023-04-07 08:16:39 -05:00

23 lines
No EOL
660 B
Python

from importlib import import_module
from . import LazyConfig, settings
config = LazyConfig()
def import_module_attr(path):
package, module = path.rsplit('.', 1)
return getattr(import_module(package), module)
def get_values():
"""
Get dictionary of values from the backend
:return:
"""
# First load a mapping between config name and default value
default_initial = ((name, options[0])
for name, options in settings.CONFIG.items())
# Then update the mapping with actually values from the backend
initial = dict(default_initial, **dict(config._backend.mget(settings.CONFIG)))
return initial