Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions django_altcha/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@

from django.conf import settings

from django_altcha.utils import lazy_static

_DEFAULTS = {
# Set to `False` to skip Altcha validation altogether.
"ALTCHA_VERIFICATION_ENABLED": True,
# This key is used to HMAC-sign ALTCHA challenges and must be kept secret.
"ALTCHA_HMAC_KEY": None,
# URL of the Altcha JavaScript file.
# Defaults to the bundled django-altcha file.
"ALTCHA_JS_URL": "/static/altcha/altcha.min.js",
"ALTCHA_JS_URL": lazy_static("altcha/altcha.min.js"),
# URL of the Altcha translations JavaScript file.
# Defaults to the bundled django-altcha file.
"ALTCHA_JS_TRANSLATIONS_URL": "/static/altcha/dist_i18n/all.min.js",
"ALTCHA_JS_TRANSLATIONS_URL": lazy_static("altcha/dist_i18n/all.min.js"),
# Whether to include Altcha translations.
# https://altcha.org/docs/v2/widget-integration/#internationalization-i18n
"ALTCHA_INCLUDE_TRANSLATIONS": False,
Expand Down
20 changes: 20 additions & 0 deletions django_altcha/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Django
from django.templatetags.static import static


def lazy_static(path):
"""
Return a lazy proxy that resolves static(path) when stringified (e.g. in templates).
This is useful to avoid AppRegistryNotReady errors in settings.
"""

class _LazyStaticUrl:
__slots__ = ("_path",)

def __init__(self, path):
self._path = path

def __str__(self):
return static(self._path)

return _LazyStaticUrl(path)
1 change: 1 addition & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
ROOT_URLCONF = "tests.urls"
ALTCHA_HMAC_KEY = "altcha-insecure-hmac-0123456789abcdef"
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
STATIC_URL = "/static/"