From 6a6ca0693c2585e88dd10cf7119303bb9a4a1d70 Mon Sep 17 00:00:00 2001 From: Josh Stegmaier <104993387+joshuastegmaier@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:26:09 -0400 Subject: [PATCH] Added Turnstile URLs to settings. Moved context processor and removed redundant processor (#2532) --- concordia/context_processors.py | 29 ---------------------- concordia/settings_template.py | 10 +++++--- concordia/turnstile/context_processor.py | 5 ---- concordia/turnstile/context_processors.py | 30 +++++++++++++++++++++++ 4 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 concordia/turnstile/context_processor.py create mode 100644 concordia/turnstile/context_processors.py diff --git a/concordia/context_processors.py b/concordia/context_processors.py index 0899dea8d..74731351d 100644 --- a/concordia/context_processors.py +++ b/concordia/context_processors.py @@ -32,32 +32,3 @@ def site_navigation(request): def maintenance_mode_frontend_available(request): value = cache.get("maintenance_mode_frontend_available", False) return {"maintenance_mode_frontend_available": value} - - -def turnstile_default_settings(request): - """ - Expose turnstile default settings to the default template context - - Cloudflare Turnstile - """ - - return { - "TURNSTILE_JS_API_URL": getattr( - settings, - "TURN_JS_API_URL", - "https://challenges.cloudflare.com/turnstile/v0/api.js", - ), - "TURNSTILE_VERIFY_URL": getattr( - settings, - "TURNSTILE_VERIFY_URL", - "https://challenges.cloudflare.com/turnstile/v0/siteverify", - ), - "TURNSTILE_SITEKEY": getattr( - settings, "TURNSTILE_SITEKEY", "1x00000000000000000000BB" - ), - "TURNSTILE_SECRET": getattr( - settings, "TURNSTILE_SECRET", "1x0000000000000000000000000000000AA" - ), - "TURNSTILE_TIMEOUT": getattr(settings, "TURNSTILE_TIMEOUT", 5), - "TURNSTILE_DEFAULT_CONFIG": getattr(settings, "TURNSTILE_DEFAULT_CONFIG", {}), - "TURNSTILE_PROXIES": getattr(settings, "TURNSTILE_PROXIES", {}), - } diff --git a/concordia/settings_template.py b/concordia/settings_template.py index 784bf0c9c..00152d977 100644 --- a/concordia/settings_template.py +++ b/concordia/settings_template.py @@ -160,7 +160,7 @@ "concordia.context_processors.system_configuration", "concordia.context_processors.site_navigation", "concordia.context_processors.maintenance_mode_frontend_available", - "concordia.context_processors.turnstile_default_settings", + "concordia.turnstile.context_processors.turnstile_default_settings", ], "libraries": { "staticfiles": "django.templatetags.static", @@ -318,8 +318,12 @@ ] # Turnstile settings -TURNSTILE_JS_API_URL = os.environ.get("TURNSTILE_JS_API_URL", "") -TURNSTILE_VERIFY_URL = os.environ.get("TURNSTILE_VERIFY_URL", "") +TURNSTILE_JS_API_URL = os.environ.get( + "TURNSTILE_JS_API_URL", "https://challenges.cloudflare.com/turnstile/v0/api.js" +) +TURNSTILE_VERIFY_URL = os.environ.get( + "TURNSTILE_VERIFY_URL", "https://challenges.cloudflare.com/turnstile/v0/siteverify" +) TURNSTILE_SITEKEY = os.environ.get("TURNSTILE_SITEKEY", "") TURNSTILE_SECRET = os.environ.get("TURNSTILE_SECRET", "") TURNSTILE_TIMEOUT = os.environ.get("TURNSTILE_TIMEOUT", 5) diff --git a/concordia/turnstile/context_processor.py b/concordia/turnstile/context_processor.py deleted file mode 100644 index ae091a422..000000000 --- a/concordia/turnstile/context_processor.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.conf import settings - - -def turnstile_settings(request): - return {"TURN_JS_API_URL": settings.TURN_JS_API_URL} diff --git a/concordia/turnstile/context_processors.py b/concordia/turnstile/context_processors.py new file mode 100644 index 000000000..ccdc65d38 --- /dev/null +++ b/concordia/turnstile/context_processors.py @@ -0,0 +1,30 @@ +from django.conf import settings + + +def turnstile_default_settings(request): + """ + Expose turnstile default settings to the default template context + - Cloudflare Turnstile + """ + + return { + "TURNSTILE_JS_API_URL": getattr( + settings, + "TURN_JS_API_URL", + "https://challenges.cloudflare.com/turnstile/v0/api.js", + ), + "TURNSTILE_VERIFY_URL": getattr( + settings, + "TURNSTILE_VERIFY_URL", + "https://challenges.cloudflare.com/turnstile/v0/siteverify", + ), + "TURNSTILE_SITEKEY": getattr( + settings, "TURNSTILE_SITEKEY", "1x00000000000000000000BB" + ), + "TURNSTILE_SECRET": getattr( + settings, "TURNSTILE_SECRET", "1x0000000000000000000000000000000AA" + ), + "TURNSTILE_TIMEOUT": getattr(settings, "TURNSTILE_TIMEOUT", 5), + "TURNSTILE_DEFAULT_CONFIG": getattr(settings, "TURNSTILE_DEFAULT_CONFIG", {}), + "TURNSTILE_PROXIES": getattr(settings, "TURNSTILE_PROXIES", {}), + }