diff --git a/notifications/models.py b/notifications/models.py index 780958f..625726e 100644 --- a/notifications/models.py +++ b/notifications/models.py @@ -11,6 +11,7 @@ else: from django.contrib.contenttypes.generic import GenericForeignKey from django.db import models +from django.db.models.query import QuerySet from django.core.exceptions import ImproperlyConfigured from django.utils.six import text_type from .utils import id2slug @@ -263,6 +264,8 @@ def notify_handler(verb, **kwargs): # Check if User or Group if isinstance(recipient, Group): recipients = recipient.user_set.all() + elif isinstance(recipient, QuerySet) or isinstance(recipient, list): + recipients = recipient else: recipients = [recipient] diff --git a/notifications/tests/tests.py b/notifications/tests/tests.py index cfc6bef..f7bc138 100644 --- a/notifications/tests/tests.py +++ b/notifications/tests/tests.py @@ -60,7 +60,7 @@ class NotificationManagersTest(TestCase): self.from_user = User.objects.create(username="from2", password="pwd", email="example@example.com") self.to_user = User.objects.create(username="to2", password="pwd", email="example@example.com") self.to_group = Group.objects.create(name="to2_g") - + self.to_user_list = User.objects.all() self.to_group.user_set.add(self.to_user) self.to_group.user_set.add(self.other_user) @@ -69,6 +69,10 @@ class NotificationManagersTest(TestCase): # Send notification to group notify.send(self.from_user, recipient=self.to_group, verb='commented', action_object=self.from_user) self.message_count += self.to_group.user_set.count() + # Send notification to user list + notify.send(self.from_user, recipient=self.to_user_list, verb='commented', action_object=self.from_user) + self.message_count += len(self.to_user_list) + def test_notify_send_return_val(self): results = notify.send(self.from_user, recipient=self.to_user, verb='commented', action_object=self.from_user)