diff --git a/notifications/models.py b/notifications/models.py index 35e95c9..7d39196 100644 --- a/notifications/models.py +++ b/notifications/models.py @@ -242,9 +242,7 @@ class Notification(models.Model): # 'NOTIFY_USE_JSONFIELD' is for backward compatibility # As app name is 'notifications', let's use 'NOTIFICATIONS' consistently from now -EXTRA_DATA = getattr(settings, 'NOTIFY_USE_JSONFIELD', None) -if EXTRA_DATA is None: - EXTRA_DATA = getattr(settings, 'NOTIFICATIONS_USE_JSONFIELD', False) +EXTRA_DATA = getattr(settings, 'NOTIFY_USE_JSONFIELD', False) or getattr(settings, 'NOTIFICATIONS_USE_JSONFIELD', False) def notify_handler(verb, **kwargs): diff --git a/notifications/tests/settings.py b/notifications/tests/settings.py index 3fa2d6a..e53262e 100644 --- a/notifications/tests/settings.py +++ b/notifications/tests/settings.py @@ -62,3 +62,4 @@ class DisableMigrations(object): return "notmigrations" MIGRATION_MODULES = DisableMigrations() +NOTIFICATIONS_USE_JSONFIELD = True diff --git a/notifications/tests/tests.py b/notifications/tests/tests.py index f7bc138..94d1135 100644 --- a/notifications/tests/tests.py +++ b/notifications/tests/tests.py @@ -72,7 +72,6 @@ class NotificationManagersTest(TestCase): # 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) @@ -365,3 +364,31 @@ class NotificationTestPages(TestCase): data = json.loads(response.content.decode('utf-8')) self.assertEqual(data['unread_count'],0) self.assertEqual(data['unread_list'],[]) + + +class NotificationTestExtraData(TestCase): + + def setUp(self): + self.message_count = 1 + self.from_user = User.objects.create_user(username="from", password="pwd", email="example@example.com") + self.to_user = User.objects.create_user(username="to", password="pwd", email="example@example.com") + self.to_user.is_staff = True + self.to_user.save() + for i in range(self.message_count): + notify.send(self.from_user, recipient=self.to_user, verb='commented', action_object=self.from_user, url="/learn/ask-a-pro/q/test-question-9/299/", other_content="Hello my 'world'") + + def logout(self): + self.client.post(reverse('admin:logout')+'?next=/', {}) + + def login(self, username, password): + self.logout() + response = self.client.post(reverse('login'), {'username': username, 'password': password}) + self.assertEqual(response.status_code, 302) + return response + + def test_extra_data(self): + self.login('to', 'pwd') + response = self.client.post(reverse('notifications:live_unread_notification_list')) + data = json.loads(response.content.decode('utf-8')) + self.assertEqual(data['unread_list'][0]['data']['url'], "/learn/ask-a-pro/q/test-question-9/299/") + self.assertEqual(data['unread_list'][0]['data']['other_content'], "Hello my 'world'") diff --git a/notifications/views.py b/notifications/views.py index bbc545a..0958659 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -155,6 +155,8 @@ def live_unread_notification_list(request): struct['target'] = str(n.target) if n.action_object: struct['action_object'] = str(n.action_object) + if n.data: + struct['data'] = n.data unread_list.append(struct) if request.GET.get('mark_as_read'): n.mark_as_read()