Merge pull request #173 from AlvaroLQueiroz/iss169

Fix #169
This commit is contained in:
Yang.Y 2017-06-04 16:24:45 +08:00 committed by GitHub
commit 5a96e4405d
2 changed files with 8 additions and 1 deletions

View file

@ -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]

View file

@ -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)