Use the get_or_create method instead of a blind create to avoid duplicated notifications for the same event when the user is subscribed to the object's event and to the global event.

Signed-off-by: Michael Price <loneviking72@gmail.com>
This commit is contained in:
Michael Price
2018-02-22 21:51:52 -04:00
committed by Roberto Rosario
parent d201f2c31c
commit 98f31ff491

View File

@@ -116,9 +116,13 @@ class EventType(object):
except PermissionDenied:
pass
else:
notification = Notification.objects.create(action=result, user=user)
notification, created = Notification.objects.get_or_create(
action=result, user=user
)
else:
notification = Notification.objects.create(action=result, user=user)
notification, created = Notification.objects.get_or_create(
action=result, user=user
)
if result.target:
content_type = ContentType.objects.get_for_model(model=result.target)
@@ -138,7 +142,10 @@ class EventType(object):
except PermissionDenied:
pass
else:
notification = Notification.objects.create(action=result, user=user)
notification, created = Notification.objects.get_or_create(
action=result, user=user
)
if not notification and result.action_object:
content_type = ContentType.objects.get_for_model(model=result.action_object)
@@ -157,7 +164,10 @@ class EventType(object):
except PermissionDenied:
pass
else:
notification = Notification.objects.create(action=result, user=user)
notification, created = Notification.objects.get_or_create(
action=result, user=user
)
def get_stored_event_type(self):
if not self.stored_event_type: