diff --git a/src/argus/htmx/appconfig.py b/src/argus/htmx/appconfig.py index b6a470a44..f9808b198 100644 --- a/src/argus/htmx/appconfig.py +++ b/src/argus/htmx/appconfig.py @@ -36,6 +36,7 @@ "context_processors": [ "argus.auth.context_processors.preferences", "argus.htmx.context_processors.static_paths", + "argus.htmx.user.context_processors.logout_context", ], "middleware": { "argus.htmx.middleware.LoginRequiredMiddleware": "end", diff --git a/src/argus/htmx/templates/htmx/user/_user_menu_logout.html b/src/argus/htmx/templates/htmx/user/_user_menu_logout.html index d9fd2004c..ce022a479 100644 --- a/src/argus/htmx/templates/htmx/user/_user_menu_logout.html +++ b/src/argus/htmx/templates/htmx/user/_user_menu_logout.html @@ -1,3 +1,4 @@ +{% include logout_modal.template_name with modal=logout_modal %}
{% csrf_token %} diff --git a/src/argus/htmx/user/context_processors.py b/src/argus/htmx/user/context_processors.py new file mode 100644 index 000000000..0296fbae5 --- /dev/null +++ b/src/argus/htmx/user/context_processors.py @@ -0,0 +1,21 @@ +""" +How to use: + +Append the "context_processors" list for the TEMPLATES-backend +``django.template.backends.django.DjangoTemplates`` with the full dotted path. + +See django settings for ``TEMPLATES``. +""" + +from django.urls import reverse + +from .views import LogoutModal + + +def logout_context(request): + return { + "logout_modal": LogoutModal( + endpoint=reverse("htmx:logout"), + dialog_id="logout-dialog", + ), + } diff --git a/src/argus/htmx/user/views.py b/src/argus/htmx/user/views.py index e4e3e56a9..9196ad235 100644 --- a/src/argus/htmx/user/views.py +++ b/src/argus/htmx/user/views.py @@ -6,6 +6,14 @@ from argus.auth.utils import get_preference_obj, save_preferences from argus.htmx.incident.views import HtmxHttpRequest +from argus.htmx.modals import ConfirmationModal + + +class LogoutModal(ConfirmationModal): + header: str = "Log out" + submit_text: str = header + button_title: str = header + explanation: str = "Log out of Argus?" @require_GET