Closes #20301: Add "Dismiss all" action to notifications dropdown #1039

Closed
opened 2026-04-05 19:57:50 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 10/17/2025

Fixes: #20301

Add a “Dismiss all” action to the bell dropdown that clears all unread notifications for the current user via a GET endpoint. The dropdown continues to show up to the most recent 10 unread items, and now includes a clear, i18n’d confirmation message that shows the total number of unread notifications affected.

Summary of changes

  • New view: NotificationDismissAllView registered with @register_model_view(Notification, name='dismiss_all', path='dismiss-all', detail=False); deletes unread notifications for request.user.

    • HTMX requests: if invoked from the Notifications page, return an HX-Redirect to repaint the page; otherwise return the existing dropdown partial.
    • Non‑HTMX requests: redirect to the Notifications page.
  • Dropdown partial context: Now passes only the top 10 unread notifications plus counts:
    notifications = request.user.notifications.unread()[:10],
    total_count = request.user.notifications.count(),
    unread_count = request.user.notifications.unread().count(). :contentReference[oaicite:1]{index=1}

  • Template update (htmx/notifications.html):
    Adds a “Dismiss all” button in the dropdown header when there are unread items, with a pluralized confirmation that shows the total unread count (e.g., “Dismiss 37 unread notifications?”).

  • HTMX utility helpers:
    Introduce htmx_current_url() and htmx_maybe_redirect_current_page() to detect the current page (via HX-Current-URL) and issue an HX-Redirect when appropriate. Both are now used by the single‑item dismiss view and the new dismiss-all view to avoid stale rows on the Notifications page. :contentReference[oaicite:3]{index=3}

Screenshots

Screenshots (notifications present)

Screenshot 2025-10-22 at 14-10-59 Subscriptions NetBox Screenshot 2025-10-22 at 14-10-41 Subscriptions NetBox

Screenshots (no notifications)

Screenshot 2025-10-17 at 00-36-58 Home NetBox Screenshot 2025-10-17 at 00-37-04 Home NetBox

Notes for reviewers

  • The button label uses “Dismiss all” to align with the route name (dismiss-all).
*Originally created by @pheus on 10/17/2025* ### Fixes: #20301 Add a **“Dismiss all”** action to the bell dropdown that clears all **unread** notifications for the current user via a GET endpoint. The dropdown continues to show up to the most recent 10 unread items, and now includes a clear, i18n’d confirmation message that shows the total number of unread notifications affected. #### Summary of changes - **New view:** `NotificationDismissAllView` registered with `@register_model_view(Notification, name='dismiss_all', path='dismiss-all', detail=False)`; deletes **unread** notifications for `request.user`. - HTMX requests: if invoked from the Notifications page, return an **`HX-Redirect`** to repaint the page; otherwise return the existing dropdown partial. - Non‑HTMX requests: redirect to the Notifications page. - **Dropdown partial context:** Now passes only the top **10** unread notifications plus counts: `notifications = request.user.notifications.unread()[:10]`, `total_count = request.user.notifications.count()`, `unread_count = request.user.notifications.unread().count()`. :contentReference[oaicite:1]{index=1} - **Template update (`htmx/notifications.html`):** Adds a “Dismiss all” button in the dropdown header when there are unread items, with a **pluralized** confirmation that shows the total unread count (e.g., “Dismiss 37 unread notifications?”). - **HTMX utility helpers:** Introduce `htmx_current_url()` and `htmx_maybe_redirect_current_page()` to detect the current page (via `HX-Current-URL`) and issue an `HX-Redirect` when appropriate. Both are now used by the single‑item `dismiss` view and the new `dismiss-all` view to avoid stale rows on the Notifications page. :contentReference[oaicite:3]{index=3} #### Screenshots **Screenshots (notifications present)** <img width="302" height="626" alt="Screenshot 2025-10-22 at 14-10-59 Subscriptions NetBox" src="https://github.com/user-attachments/assets/ab9dc1fc-1cf2-4259-971e-df0c977ff16f" /> <img width="302" height="626" alt="Screenshot 2025-10-22 at 14-10-41 Subscriptions NetBox" src="https://github.com/user-attachments/assets/70f47a83-1582-4f3a-a82d-0054b2bd5982" /> **Screenshots (no notifications)** <img width="302" height="78" alt="Screenshot 2025-10-17 at 00-36-58 Home NetBox" src="https://github.com/user-attachments/assets/98cf4705-20c0-44e5-a9e1-3daf836a1cd8" /> <img width="302" height="78" alt="Screenshot 2025-10-17 at 00-37-04 Home NetBox" src="https://github.com/user-attachments/assets/ad5bf3cf-cc37-418e-b411-9fde9cb46952" /> --- #### Notes for reviewers - The button label uses **“Dismiss all”** to align with the route name (`dismiss-all`).
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#1039