Skip to content

Commit d149c12

Browse files
committed
add logout modal button to global context
1 parent f4d0e1e commit d149c12

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

src/argus/htmx/appconfig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"context_processors": [
3737
"argus.auth.context_processors.preferences",
3838
"argus.htmx.context_processors.static_paths",
39+
"argus.htmx.user.context_processors.logout_context",
3940
],
4041
"middleware": {
4142
"argus.htmx.middleware.LoginRequiredMiddleware": "end",

src/argus/htmx/templates/htmx/user/_user_menu_logout.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{% include logout_modal.template_name with modal=logout_modal %}
12
<form class="flex" action="{% url "htmx:logout" %}" method="post">
23
{% csrf_token %}
34
<button class="flex-1 text-start" type="submit">Log out</button>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
How to use:
3+
4+
Append the "context_processors" list for the TEMPLATES-backend
5+
``django.template.backends.django.DjangoTemplates`` with the full dotted path.
6+
7+
See django settings for ``TEMPLATES``.
8+
"""
9+
10+
from django.urls import reverse
11+
12+
from .views import LogoutModal
13+
14+
15+
def logout_context(request):
16+
return {
17+
"logout_modal": LogoutModal(
18+
endpoint=reverse("htmx:logout"),
19+
dialog_id="logout-dialog",
20+
),
21+
}

src/argus/htmx/user/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
from argus.auth.utils import get_preference_obj, save_preferences
88
from argus.htmx.incident.views import HtmxHttpRequest
9+
from argus.htmx.modals import ConfirmationModal
10+
11+
12+
class LogoutModal(ConfirmationModal):
13+
header: str = "Log out"
14+
submit_text: str = header
15+
button_title: str = header
16+
explanation: str = "Log out of Argus?"
917

1018

1119
@require_GET

0 commit comments

Comments
 (0)