mirror of
https://github.com/Hopiu/django-notifications.git
synced 2026-03-16 21:30:24 +00:00
Fix #158
This commit is contained in:
parent
37bb7f6ade
commit
339b064f3f
4 changed files with 32 additions and 4 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -62,3 +62,4 @@ class DisableMigrations(object):
|
|||
return "notmigrations"
|
||||
|
||||
MIGRATION_MODULES = DisableMigrations()
|
||||
NOTIFICATIONS_USE_JSONFIELD = True
|
||||
|
|
|
|||
|
|
@ -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'")
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue