From a440f98175d2d236060a0aa7d0aab2a55c123288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Wed, 20 Oct 2021 13:28:13 +0200 Subject: [PATCH] allow to set target proxy objects --- notifications/base/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/notifications/base/models.py b/notifications/base/models.py index c643cfa..5c2658b 100644 --- a/notifications/base/models.py +++ b/notifications/base/models.py @@ -324,6 +324,7 @@ def notify_handler(verb, **kwargs): timestamp = kwargs.pop('timestamp', timezone.now()) Notification = load_model('notifications', 'Notification') level = kwargs.pop('level', Notification.LEVELS.info) + actor_for_concrete_model = kwargs.pop('actor_for_concrete_model', True) # Check if User or Group if isinstance(recipient, Group): @@ -338,7 +339,7 @@ def notify_handler(verb, **kwargs): for recipient in recipients: newnotify = Notification( recipient=recipient, - actor_content_type=ContentType.objects.get_for_model(actor), + actor_content_type=ContentType.objects.get_for_model(actor, for_concrete_model=actor_for_concrete_model), actor_object_id=actor.pk, verb=str(verb), public=public, @@ -350,9 +351,10 @@ def notify_handler(verb, **kwargs): # Set optional objects for obj, opt in optional_objs: if obj is not None: + for_concrete_model = kwargs.pop(f'{opt}_for_concrete_model', True) setattr(newnotify, '%s_object_id' % opt, obj.pk) setattr(newnotify, '%s_content_type' % opt, - ContentType.objects.get_for_model(obj)) + ContentType.objects.get_for_model(obj, for_concrete_model=for_concrete_model)) if kwargs and EXTRA_DATA: newnotify.data = kwargs.copy()