From 955f39da73a5b41711e74dfcc2b111d9d3deec07 Mon Sep 17 00:00:00 2001 From: Mounir Messelmeni Date: Thu, 4 Sep 2025 14:02:13 +0200 Subject: [PATCH] Update docs --- axes/helpers.py | 1 + docs/4_configuration.rst | 2 +- docs/5_customization.rst | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/axes/helpers.py b/axes/helpers.py index 8347974..a0a195e 100644 --- a/axes/helpers.py +++ b/axes/helpers.py @@ -476,6 +476,7 @@ def get_lockout_response( return settings.AXES_LOCKOUT_CALLABLE(request, credentials) if isinstance(settings.AXES_LOCKOUT_CALLABLE, str): callable_obj = import_string(settings.AXES_LOCKOUT_CALLABLE) + # Try calling with 3 args, fallback to 2 for backward compatibility try: return callable_obj(request, original_response, credentials) except TypeError: diff --git a/docs/4_configuration.rst b/docs/4_configuration.rst index de060b9..36c4af5 100644 --- a/docs/4_configuration.rst +++ b/docs/4_configuration.rst @@ -53,7 +53,7 @@ The following ``settings.py`` options are available for customizing Axes behavio +------------------------------------------------------+----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | AXES_WHITELIST_CALLABLE | None | A callable or a string path to callable that takes two arguments for whitelisting determination and returns True, if user should be whitelisted: ``def is_whitelisted(request: HttpRequest, credentials: dict) -> bool: ...``. This can be any callable similarly to ``AXES_USERNAME_CALLABLE``. | +------------------------------------------------------+----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| AXES_LOCKOUT_CALLABLE | None | A callable or a string path to callable that takes two arguments returns a response. For example: ``def generate_lockout_response(request: HttpRequest, credentials: dict) -> HttpResponse: ...``. This can be any callable similarly to ``AXES_USERNAME_CALLABLE``. If not callable is defined, then the default implementation in ``axes.helpers.get_lockout_response`` is used for determining the correct lockout response that is sent to the requesting client. | +| AXES_LOCKOUT_CALLABLE | None | A callable or a string path to callable that takes three arguments returns a response. For example: ``def generate_lockout_response(request: HttpRequest, original_response: HttpResponse, credentials: dict) -> HttpResponse: ...``. This can be any callable similarly to ``AXES_USERNAME_CALLABLE``. If not callable is defined, then the default implementation in ``axes.helpers.get_lockout_response`` is used for determining the correct lockout response that is sent to the requesting client. | +------------------------------------------------------+----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | AXES_CLIENT_IP_CALLABLE | None | A callable or a string path to callable that takes HttpRequest as an argument and returns the resolved IP as a response. For example: ``def get_ip(request: HttpRequest) -> str: ...``. This can be any callable similarly to ``AXES_USERNAME_CALLABLE``. If not callable is defined, then the default implementation in ``axes.helpers.get_client_ip_address`` is used. | +------------------------------------------------------+----------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ diff --git a/docs/5_customization.rst b/docs/5_customization.rst index a1fbcfd..ec66f95 100644 --- a/docs/5_customization.rst +++ b/docs/5_customization.rst @@ -166,7 +166,7 @@ An example of usage could be e.g. a custom view for processing lockouts. from django.http import JsonResponse - def lockout(request, credentials, *args, **kwargs): + def lockout(request, response, credentials, *args, **kwargs): return JsonResponse({"status": "Locked out due to too many login failures"}, status=403) ``settings.py``::