Merge branch '25-delete-notifications' into 'master'
feature: sends notifications to subscribers post delete Closes #25 See merge request djangoldp-packages/djangoldp-notification!27
This commit is contained in:
commit
b615899121
@ -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"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user