-
Couldn't load subscription status.
- Fork 2.9k
Closes #20301: Add "Dismiss all" action to notifications dropdown #20612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pheus
wants to merge
1
commit into
netbox-community:main
Choose a base branch
from
pheus:20301-add-clear-all-option-to-user-notifications-dropdown
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| from django.contrib.contenttypes.models import ContentType | ||
| from django.core.paginator import EmptyPage | ||
| from django.db.models import Count, Q | ||
| from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponse | ||
| from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponse, Http404 | ||
| from django.shortcuts import get_object_or_404, redirect, render | ||
| from django.urls import reverse | ||
| from django.utils import timezone | ||
|
|
@@ -25,7 +25,7 @@ | |
| from netbox.views import generic | ||
| from netbox.views.generic.mixins import TableMixin | ||
| from utilities.forms import ConfirmationForm, get_field_value | ||
| from utilities.htmx import htmx_partial | ||
| from utilities.htmx import htmx_partial, htmx_maybe_redirect_current_page | ||
| from utilities.paginator import EnhancedPaginator, get_paginate_count | ||
| from utilities.query import count_related | ||
| from utilities.querydict import normalize_querydict | ||
|
|
@@ -518,8 +518,9 @@ class NotificationsView(LoginRequiredMixin, View): | |
| """ | ||
| def get(self, request): | ||
| return render(request, 'htmx/notifications.html', { | ||
| 'notifications': request.user.notifications.unread(), | ||
| 'notifications': request.user.notifications.unread()[:10], | ||
| 'total_count': request.user.notifications.count(), | ||
|
Comment on lines
-521
to
522
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During manual testing, I've noticed that the dropdown menu does not actually limit the notification. |
||
| 'unread_count': request.user.notifications.unread().count(), | ||
| }) | ||
|
|
||
|
|
||
|
|
@@ -528,6 +529,7 @@ class NotificationReadView(LoginRequiredMixin, View): | |
| """ | ||
| Mark the Notification read and redirect the user to its attached object. | ||
| """ | ||
|
|
||
| def get(self, request, pk): | ||
| # Mark the Notification as read | ||
| notification = get_object_or_404(request.user.notifications, pk=pk) | ||
|
|
@@ -541,18 +543,48 @@ def get(self, request, pk): | |
| return redirect('account:notifications') | ||
|
|
||
|
|
||
| @register_model_view(Notification, name='dismiss_all', path='dismiss-all', detail=False) | ||
| class NotificationDismissAllView(LoginRequiredMixin, View): | ||
| """ | ||
| Convenience view to clear all *unread* notifications for the current user. | ||
| """ | ||
|
|
||
| def get(self, request): | ||
| request.user.notifications.unread().delete() | ||
| if htmx_partial(request): | ||
| # If a user is currently on the notification page, redirect there (full repaint) | ||
| redirect_resp = htmx_maybe_redirect_current_page(request, 'account:notifications', preserve_query=True) | ||
| if redirect_resp: | ||
| return redirect_resp | ||
|
|
||
| return render(request, 'htmx/notifications.html', { | ||
| 'notifications': request.user.notifications.unread()[:10], | ||
| 'total_count': request.user.notifications.count(), | ||
| 'unread_count': request.user.notifications.unread().count(), | ||
| }) | ||
| return redirect('account:notifications') | ||
|
|
||
|
|
||
| @register_model_view(Notification, 'dismiss') | ||
| class NotificationDismissView(LoginRequiredMixin, View): | ||
| """ | ||
| A convenience view which allows deleting notifications with one click. | ||
| """ | ||
|
|
||
| def get(self, request, pk): | ||
| notification = get_object_or_404(request.user.notifications, pk=pk) | ||
| notification.delete() | ||
|
|
||
| if htmx_partial(request): | ||
| # If a user is currently on the notification page, redirect there (full repaint) | ||
| redirect_resp = htmx_maybe_redirect_current_page(request, 'account:notifications', preserve_query=True) | ||
| if redirect_resp: | ||
| return redirect_resp | ||
|
|
||
| return render(request, 'htmx/notifications.html', { | ||
| 'notifications': request.user.notifications.unread()[:10], | ||
| 'total_count': request.user.notifications.count(), | ||
| 'unread_count': request.user.notifications.unread().count(), | ||
| }) | ||
|
|
||
| return redirect('account:notifications') | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This is an unrelated fix.
Http404is used, but not imported.