From 1c8118304fe6f1dfd2bb779a284fc98c3836b62e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 4 Jul 2024 12:29:51 -0400 Subject: [PATCH] Include total notification count in dropdown --- netbox/extras/views.py | 15 ++------------- netbox/templates/htmx/notifications.html | 8 ++++++-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/netbox/extras/views.py b/netbox/extras/views.py index eacab2bcc..13f271329 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -409,22 +409,11 @@ class NotificationGroupBulkDeleteView(generic.BulkDeleteView): class NotificationsView(LoginRequiredMixin, View): def get(self, request): - notifications = Notification.objects.filter( - user=request.user, - read__isnull=True - ) return render(request, 'htmx/notifications.html', { - 'notifications': notifications, + 'notifications': request.user.notifications.unread(), + 'total_count': request.user.notifications.count(), }) - def post(self, request): - form = forms.RenderMarkdownForm(request.POST) - if not form.is_valid(): - HttpResponseBadRequest() - rendered = render_markdown(form.cleaned_data['text']) - - return HttpResponse(rendered) - @register_model_view(Notification, 'read') class NotificationReadView(LoginRequiredMixin, View): diff --git a/netbox/templates/htmx/notifications.html b/netbox/templates/htmx/notifications.html index 14d2f7130..c9230b81e 100644 --- a/netbox/templates/htmx/notifications.html +++ b/netbox/templates/htmx/notifications.html @@ -19,6 +19,10 @@ {% trans "No unread notifications" %} {% endfor %} + {% if total_count %} + + {% trans "All notifications" %} + {% badge total_count %} + + {% endif %} - -{% trans "All notifications" %}