Skip to content
Draft
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
1 change: 1 addition & 0 deletions src/argus/htmx/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"context_processors": [
"argus.auth.context_processors.preferences",
"argus.htmx.context_processors.static_paths",
"argus.htmx.user.context_processors.logout_context",
],
Comment on lines +39 to 40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like how the context processor is automatically added through appconfig

"middleware": {
"argus.htmx.middleware.LoginRequiredMiddleware": "end",
Expand Down
1 change: 1 addition & 0 deletions src/argus/htmx/templates/htmx/user/_user_menu_logout.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% include logout_modal.template_name with modal=logout_modal %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks weird. would be much better if it was possible to just write {{ logout_modal }}

Copy link
Contributor Author

@hmpf hmpf Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my ultimate goal but I've been struggling to make the csrf token/context outside of the modal itself available to the template. Therefore I'm working to finish everything else while doing the occasional web search for clues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does django forms do this?

Copy link
Contributor Author

@hmpf hmpf Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The form way is what I've been doing so far, which is why I inherit from RenderableMixin. Just doing that doesn't make csrf_token available...

<form class="flex" action="{% url "htmx:logout" %}" method="post">
{% csrf_token %}
<button class="flex-1 text-start" type="submit">Log out</button>
Expand Down
21 changes: 21 additions & 0 deletions src/argus/htmx/user/context_processors.py
Original file line number Diff line number Diff line change
@@ -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``.
"""
Comment on lines +1 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need something to indicate that if you're using appconfig.py, the context processors are already added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. this is copypasted from another context processor so there would be more places to change. Separate PR I think.


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",
),
}
8 changes: 8 additions & 0 deletions src/argus/htmx/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading