Fixes #17097: Record static object representation when calling NotificationGroup.notify() (#17161)

* Fixes #17097: Record static object representation when calling NotificationGroup.notify()

* Redirect to notifications list when marking as read notifications for deleted objects

* Link to object in notifications dropdown only for non-destructive events
This commit is contained in:
Jeremy Stretch
2024-08-15 12:04:19 -04:00
committed by GitHub
parent b6071a80d9
commit dd3166a4ed
3 changed files with 12 additions and 2 deletions

View File

@@ -424,11 +424,16 @@ 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)
notification.read = timezone.now()
notification.save()
return redirect(notification.object.get_absolute_url())
# Redirect to the object if it has a URL (deleted objects will not)
if hasattr(notification.object, 'get_absolute_url'):
return redirect(notification.object.get_absolute_url())
return redirect('account:notifications')
@register_model_view(Notification, 'dismiss')