diff --git a/notifications/models.py b/notifications/models.py index e3205f9c495ecc0fc3ba2854df2447fb14ce4ece..49c6bdd1c11b1336bb84fc1fba934a77f5e48826 100644 --- a/notifications/models.py +++ b/notifications/models.py @@ -85,7 +85,7 @@ class Notification(models.Model): current timestamp. """ from django.utils.timesince import timesince as timesince_ - return timesince_(self.timestamp, now) + return timesince_(self.created, now) @property def slug(self): diff --git a/notifications/urls.py b/notifications/urls.py index 7386359ef687e45b38e17ba8cb062d6b63eaa761..cd551b2adf6f5b21ffb07b4bdcfaa51cb3a1f372 100644 --- a/notifications/urls.py +++ b/notifications/urls.py @@ -13,6 +13,6 @@ urlpatterns = [ url(r'^delete/(?P<slug>\d+)/$', views.delete, name='delete'), url(r'^api/unread_count/$', views.live_unread_notification_count, name='live_unread_notification_count'), - url(r'^api/unread_list/$', views.live_unread_notification_list, + url(r'^api/list/$', views.live_notification_list, name='live_unread_notification_list'), ] diff --git a/notifications/views.py b/notifications/views.py index a3b88a85ad23bc0ee673fc9cbb885e1119f50bd7..2170da02f09e20d7ae8dd75078e9cb6fd75a448b 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -102,11 +102,11 @@ def live_unread_notification_count(request): return JsonResponse(data) -def live_unread_notification_list(request): +def live_notification_list(request): if not request.user.is_authenticated(): data = { 'unread_count': 0, - 'unread_list': [] + 'list': [] } return JsonResponse(data) @@ -117,9 +117,9 @@ def live_unread_notification_list(request): except ValueError: num_to_fetch = 5 - unread_list = [] + list = [] - for n in request.user.notifications.unread()[:num_to_fetch]: + for n in request.user.notifications.all()[:num_to_fetch]: struct = model_to_dict(n) struct['slug'] = id2slug(n.id) if n.actor: @@ -130,11 +130,11 @@ def live_unread_notification_list(request): if n.action_object: struct['action_object'] = str(n.action_object) - unread_list.append(struct) + list.append(struct) if request.GET.get('mark_as_read'): n.mark_as_read() data = { 'unread_count': request.user.notifications.unread().count(), - 'unread_list': unread_list + 'list': list } return JsonResponse(data) diff --git a/scipost/static/scipost/assets/js/notifications.js b/scipost/static/scipost/assets/js/notifications.js index dfc34078400f3692ffa6257411242c51c0b430c2..14ef93ed960d12deaa7efc018914dbbd7482835b 100644 --- a/scipost/static/scipost/assets/js/notifications.js +++ b/scipost/static/scipost/assets/js/notifications.js @@ -1,7 +1,7 @@ var notify_badge_class = 'live_notify_badge'; var notify_menu_class = 'live_notify_list'; var notify_api_url_count = '/notifications/api/unread_count/'; -var notify_api_url_list = '/notifications/api/unread_list/'; +var notify_api_url_list = '/notifications/api/list/'; var notify_fetch_count = '5'; var notify_refresh_period = 15000; var consecutive_misfires = 0; @@ -20,7 +20,7 @@ function fill_notification_badge(data) { function get_notification_list() { var data = fetch_api_data(notify_api_url_list, function(data) { - var messages = data.unread_list.map(function (item) { + var messages = data.list.map(function (item) { var message = ""; if(typeof item.actor !== 'undefined'){ message = '<strong>' + item.actor + '</strong>'; @@ -39,7 +39,9 @@ function get_notification_list() { message = message + " " + item.timestamp; } return '<li class="list-group-item ' + (item.unread ? ' active' : '') + '">' + message + '</li>'; - }).join('') + }).join(''); + + if (messages == '') { messages = 'You have no notifications.' } document.getElementById('notification-list').innerHTML = messages; }); @@ -93,7 +95,7 @@ $(function(){ } var get_notifications = function() { - var _str = '<ul id="notification-list" class="update_notifications list-group"><div class="w-100 text-center"><i class="fa fa-circle-o-notch fa-spin fa-fw"></i><span class="sr-only">Loading...</span></div></ul>'; + var _str = '<ul id="notification-list" class="update_notifications list-group"><div class="w-100 text-center py-4"><i class="fa fa-circle-o-notch fa-2x fa-spin fa-fw"></i><span class="sr-only">Loading...</span></div></ul>'; get_notification_list(); return _str; }