diff --git a/README.rst b/README.rst index 657f529..d6f824b 100644 --- a/README.rst +++ b/README.rst @@ -59,5 +59,5 @@ The default prefix for flags is `FRONTEND_`, if you like to change it you can do FRONTEND_SETTINGS = { "WAFFLE_FLAG_PREFIX": "FRONTEND_", # Prefix used to filter out the flag that should be exposed in the endpoint - "CONSTANCE_KEY": "FRONTEND_SETTINGS", # Name of the settings in constance + "CONSTANCE_KEY_PREFIX": "FRONTEND_", # Prefix used to filter out the settings in constance } diff --git a/frontend_settings/settings.py b/frontend_settings/settings.py index 355391f..66ed297 100644 --- a/frontend_settings/settings.py +++ b/frontend_settings/settings.py @@ -4,7 +4,7 @@ DEFAULTS = { "WAFFLE_FLAG_PREFIX": "FRONTEND_", - "CONSTANCE_KEY": "FRONTEND_SETTINGS", + "CONSTANCE_KEY_PREFIX": "FRONTEND_", } USER_SETTINGS = getattr(dj_settings, "FRONTEND_SETTINGS", None) @@ -14,7 +14,7 @@ class APISettings(_APISettings): WAFFLE_FLAG_PREFIX: str - CONSTANCE_KEY: str + CONSTANCE_KEY_PREFIX: str @property def user_settings(self): diff --git a/frontend_settings/utils.py b/frontend_settings/utils.py index 9b4ed53..040cbc4 100644 --- a/frontend_settings/utils.py +++ b/frontend_settings/utils.py @@ -18,8 +18,9 @@ def get_flags(request: HttpRequest) -> Dict[str, bool]: def get_settings() -> Dict[str, Any]: - constance_key: str = settings.CONSTANCE_KEY + constance_key_prefix: str = settings.CONSTANCE_KEY_PREFIX return { - key: getattr(constance_config, key, None) - for key in getattr(constance_config, constance_key, []) + key.replace(constance_key_prefix, ""): getattr(constance_config, key, None) + for key in dir(constance_config) + if key.startswith(constance_key_prefix) } diff --git a/tests/settings.py b/tests/settings.py index 264a9d3..dafdf08 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -23,11 +23,14 @@ ALLOWED_HOSTS = ("*",) CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend" -FRONTEND_SETTINGS = {"WAFFLE_FLAG_PREFIX": "TEST_", "CONSTANCE_KEY": "TEST_FRONTEND"} +FRONTEND_SETTINGS = { + "WAFFLE_FLAG_PREFIX": "TEST_", + "CONSTANCE_KEY_PREFIX": "TEST_FRONTEND_", +} + CONSTANCE_CONFIG = { - "TEST_FRONTEND": (["SETTINGS_AAA", "SETTINGS_BBB", "SETTINGS_CCC"], ""), - "SETTINGS_AAA": ("VALUE AAA", ""), - "SETTINGS_BBB": ("VALUE BBB", ""), - "SETTINGS_CCC": ("VALUE CCC", ""), + "TEST_FRONTEND_SETTING_AAA": ("VALUE AAA", ""), + "TEST_FRONTEND_SETTING_BBB": ("VALUE BBB", ""), + "TEST_FRONTEND_SETTING_CCC": ("VALUE CCC", ""), "NOT_FRONTEND": ("NOT ON SETTINGS", ""), } diff --git a/tests/test_views.py b/tests/test_views.py index d864377..9ba212b 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -80,7 +80,7 @@ def test_return_settings(client): response = client.get(url) data = response.data["settings"] - assert data["SETTINGS_AAA"] == "VALUE AAA" - assert data["SETTINGS_BBB"] == "VALUE BBB" - assert data["SETTINGS_CCC"] == "VALUE CCC" + assert data["SETTING_AAA"] == "VALUE AAA" + assert data["SETTING_BBB"] == "VALUE BBB" + assert data["SETTING_CCC"] == "VALUE CCC" assert "NOT_FRONTEND" not in data