From b87d9a0d87bedee2a974078010e6581239038a37 Mon Sep 17 00:00:00 2001
From: Calum Mackervoy <c.mackervoy@gmail.com>
Date: Mon, 1 Jun 2020 19:49:28 +0000
Subject: [PATCH] feature: sends notifications to subscribers post delete

---
 djangoldp_notification/models.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/djangoldp_notification/models.py b/djangoldp_notification/models.py
index db59ceb..6915b82 100644
--- a/djangoldp_notification/models.py
+++ b/djangoldp_notification/models.py
@@ -4,7 +4,7 @@ import requests
 from django.conf import settings
 from django.core.mail import send_mail
 from django.db import models
-from django.db.models.signals import post_save
+from django.db.models.signals import post_save, post_delete
 from django.dispatch import receiver
 from django.template import loader
 from django.urls import NoReverseMatch
@@ -87,9 +87,11 @@ class Subscription(Model):
 
         super(Subscription, self).save(*args, **kwargs)
 
+
 # --- SUBSCRIPTION SYSTEM ---
 @receiver(post_save, dispatch_uid="callback_notif")
-def send_notification(sender, instance, created, **kwargs):
+@receiver(post_delete, dispatch_uid="delete_callback_notif")
+def send_notification(sender, instance, **kwargs):
     if sender != Notification:
         threads = []
         try:
@@ -101,13 +103,14 @@ def send_notification(sender, instance, created, **kwargs):
         # dispatch a notification for every Subscription on this resource
         for subscription in Subscription.objects.filter(models.Q(object=url_resource) | models.Q(object=url_container)):
             if not instance.is_backlink:
-                process = Thread(target=send_request, args=[subscription.inbox, url_resource, instance, created])
+                process = Thread(target=send_request, args=[subscription.inbox, url_resource, instance,
+                                                            kwargs.get("created", False)])
                 process.start()
                 threads.append(process)
 
 
 def send_request(target, object_iri, instance, created):
-    unknown = _("Auteur inconnu")
+    unknown = str(_("Auteur inconnu"))
     author = getattr(getattr(instance, MODEL_MODIFICATION_USER_FIELD, unknown), "urlid", unknown)
     request_type = "creation" if created else "update"
 
-- 
GitLab