Skip to content
Snippets Groups Projects
Commit e6e52599 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch 'constance-usable-in-settings' into 'master'

Make constance configs usable in other settings

See merge request AlekSIS/AlekSIS!118
parents e503ac41 a09481d0
No related branches found
No related tags found
1 merge request!118Make constance configs usable in other settings
Pipeline #636 failed
......@@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _
from dynaconf import LazySettings
from easy_thumbnails.conf import Settings as thumbnail_settings
from .util.core_helpers import get_app_packages, merge_app_settings
from .util.core_helpers import get_app_packages, lazy_config, merge_app_settings
ENVVAR_PREFIX_FOR_DYNACONF = "ALEKSIS"
DIRS_FOR_DYNACONF = ["/etc/aleksis"]
......@@ -368,7 +368,7 @@ _settings.populate_obj(sys.modules[__name__])
PWA_APP_NAME = "AlekSIS" # dbsettings
PWA_APP_DESCRIPTION = "AlekSIS – The free school information system" # dbsettings
PWA_APP_THEME_COLOR = _settings.get("pwa.color", "#da1f3d") # dbsettings
PWA_APP_THEME_COLOR = lazy_config("COLOUR_PRIMARY")
PWA_APP_BACKGROUND_COLOR = "#ffffff"
PWA_APP_DISPLAY = "standalone"
PWA_APP_SCOPE = "/"
......
import pkgutil
from importlib import import_module
from typing import Sequence, Union
from typing import Any, Callable, Sequence, Union
from django.conf import settings
from django.db.models import Model
from django.http import HttpRequest
from django.utils.functional import lazy
def dt_show_toolbar(request: HttpRequest) -> bool:
......@@ -67,6 +68,20 @@ def merge_app_settings(setting: str, original: Union[dict, list], deduplicate: b
raise TypeError("Only dict and list settings can be merged.")
def lazy_config(key: str) -> Callable[[str], Any]:
""" Lazily get a config value from constance. Useful to bind constance
configs to other global settings to make them available to third-party
apps that are not aware of constance.
"""
def _get_config(key: str) -> Any:
from constance import config # noqa
return getattr(config, key)
# The type is guessed from the default value to improve lazy()'s behaviour
return lazy(_get_config, type(settings.CONSTANCE_CONFIG[key][0]))(key)
def is_impersonate(request: HttpRequest) -> bool:
if hasattr(request, "user"):
return getattr(request.user, "is_impersonate", False)
......
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