Include total notification count in dropdown

This commit is contained in:
Jeremy Stretch 2024-07-04 12:29:51 -04:00
parent 29675d6e45
commit 1c8118304f
2 changed files with 8 additions and 15 deletions

View File

@ -409,22 +409,11 @@ class NotificationGroupBulkDeleteView(generic.BulkDeleteView):
class NotificationsView(LoginRequiredMixin, View): class NotificationsView(LoginRequiredMixin, View):
def get(self, request): def get(self, request):
notifications = Notification.objects.filter(
user=request.user,
read__isnull=True
)
return render(request, 'htmx/notifications.html', { 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') @register_model_view(Notification, 'read')
class NotificationReadView(LoginRequiredMixin, View): class NotificationReadView(LoginRequiredMixin, View):

View File

@ -19,6 +19,10 @@
{% trans "No unread notifications" %} {% trans "No unread notifications" %}
</div> </div>
{% endfor %} {% endfor %}
{% if total_count %}
<a href="{% url 'account:notifications' %}" class="list-group-item list-group-item-action d-flex justify-content-between p-2">
{% trans "All notifications" %}
{% badge total_count %}
</a>
{% endif %}
</div> </div>
<hr class="dropdown-divider" />
<a href="{% url 'account:notifications' %}" class="dropdown-item">{% trans "All notifications" %}</a>