mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 16:48:16 -06:00
Enable one-click dismissals from notifications list
This commit is contained in:
parent
9c875716f7
commit
29675d6e45
13
netbox/extras/tables/columns.py
Normal file
13
netbox/extras/tables/columns.py
Normal file
@ -0,0 +1,13 @@
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from netbox.tables.columns import ActionsColumn, ActionsItem
|
||||
|
||||
__all__ = (
|
||||
'NotificationActionsColumn',
|
||||
)
|
||||
|
||||
|
||||
class NotificationActionsColumn(ActionsColumn):
|
||||
actions = {
|
||||
'dismiss': ActionsItem(_('Dismiss'), 'trash-can-outline', 'delete', 'danger'),
|
||||
}
|
@ -7,6 +7,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from extras.models import *
|
||||
from netbox.constants import EMPTY_TABLE_TEXT
|
||||
from netbox.tables import BaseTable, NetBoxTable, columns
|
||||
from .columns import NotificationActionsColumn
|
||||
|
||||
__all__ = (
|
||||
'BookmarkTable',
|
||||
@ -303,8 +304,8 @@ class NotificationTable(NetBoxTable):
|
||||
timespec='minutes',
|
||||
verbose_name=_('Read'),
|
||||
)
|
||||
actions = columns.ActionsColumn(
|
||||
actions=('delete',)
|
||||
actions = NotificationActionsColumn(
|
||||
actions=('dismiss',)
|
||||
)
|
||||
|
||||
class Meta(NetBoxTable.Meta):
|
||||
|
@ -432,7 +432,7 @@ class NotificationReadView(LoginRequiredMixin, View):
|
||||
Mark the Notification read and redirect the user to its attached object.
|
||||
"""
|
||||
def get(self, request, pk):
|
||||
notification = get_object_or_404(Notification, pk=pk)
|
||||
notification = get_object_or_404(request.user.notifications, pk=pk)
|
||||
notification.read = timezone.now()
|
||||
notification.save()
|
||||
|
||||
@ -445,12 +445,15 @@ class NotificationDismissView(LoginRequiredMixin, View):
|
||||
A convenience view which allows deleting notifications with one click.
|
||||
"""
|
||||
def get(self, request, pk):
|
||||
request.user.notifications.filter(pk=pk).delete()
|
||||
notification = get_object_or_404(request.user.notifications, pk=pk)
|
||||
notification.delete()
|
||||
|
||||
notifications = request.user.notifications.unread()[:10]
|
||||
return render(request, 'htmx/notifications.html', {
|
||||
'notifications': notifications,
|
||||
})
|
||||
if htmx_partial(request):
|
||||
return render(request, 'htmx/notifications.html', {
|
||||
'notifications': request.user.notifications.unread()[:10],
|
||||
})
|
||||
|
||||
return redirect('account:notifications')
|
||||
|
||||
|
||||
@register_model_view(Notification, 'delete')
|
||||
|
Loading…
Reference in New Issue
Block a user