update: subscription for containers and resources

This commit is contained in:
Matthieu Fesselier 2019-04-24 14:56:18 +07:00
parent 4d4b21e7e8
commit d8ae6c1c75
1 changed files with 5 additions and 4 deletions

View File

@ -54,11 +54,12 @@ class Subscription(Model):
# --- SUBSCRIPTION SYSTEM --- # --- SUBSCRIPTION SYSTEM ---
@receiver(post_save, dispatch_uid="callback_notif") @receiver(post_save, dispatch_uid="callback_notif")
def send_notification(sender, instance, **kwargs): def send_notification(sender, instance, **kwargs):
if sender != Notification and isinstance(sender, Model): if sender != Notification and issubclass(sender, Model):
threads = [] threads = []
url = settings.BASE_URL + Model.resource_id(instance) + '/' urlContainer = settings.BASE_URL + Model.container_id(instance)
for subscription in Subscription.objects.filter(object=url): urlResource = settings.BASE_URL + Model.resource_id(instance)
process = Thread(target=send_request, args=[subscription.inbox, url]) for subscription in Subscription.objects.filter(models.Q(object=urlResource)|models.Q(object=urlContainer)):
process = Thread(target=send_request, args=[subscription.inbox, urlResource])
process.start() process.start()
threads.append(process) threads.append(process)