From 8a9b8804f60634a4a963777ce27464c693e418a6 Mon Sep 17 00:00:00 2001 From: fbormann Date: Wed, 26 Oct 2016 11:59:44 -0300 Subject: [PATCH] bug finished, I've added support for odd numbers and updates are correct --- core/static/js/base/amadeus.js | 15 ++++++++++----- core/templates/notifications.html | 4 ++-- core/views.py | 11 +++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/core/static/js/base/amadeus.js b/core/static/js/base/amadeus.js index ad43fe5..d28891c 100644 --- a/core/static/js/base/amadeus.js +++ b/core/static/js/base/amadeus.js @@ -91,10 +91,15 @@ This functions get the next 5 notifications from the user given a "step"(an amou function getNotifications(step){ $.get('/getNotifications', {'steps':step, 'amount': 5}, function(data){ - $("#notification-dropdown").append(data); - $('#notification-see-more').remove(); - var seemore = '
  • '; - $("#notification-dropdown").append(seemore); - $("#notification-count").text(step+5); + if(data == "nothing"){ + console.log("No notifications"); + }else{ + $("#notification-dropdown").append(data['html']); + $('#notification-see-more').remove(); + var seemore = '
  • '; + $("#notification-dropdown").append(seemore); + $("#notification-count").text(step+data['amountGotten']); + } + }); } diff --git a/core/templates/notifications.html b/core/templates/notifications.html index 1dea4c8..6821424 100644 --- a/core/templates/notifications.html +++ b/core/templates/notifications.html @@ -14,7 +14,7 @@
    {{ notification.datetime|timesince }}
    -

    {{ notification.message }}

    +

    {{notification.actor.username}} {{ notification.message }}

    @@ -30,7 +30,7 @@
    {{ notification.datetime|timesince }}
    -

    {{ notification.message }}

    +

    {{notification.actor.username}} {{ notification.message }}

    diff --git a/core/views.py b/core/views.py index 28bb7ce..87fb4d4 100644 --- a/core/views.py +++ b/core/views.py @@ -101,17 +101,24 @@ def processNotification(self, notificationId): def getNotifications(request): context = {} if request.user.is_authenticated: - + amountGotten = 0 #amountOfNotifications actually received steps = int(request.GET['steps']) amount = int(request.GET['amount']) notifications = Notification.objects.filter(user= request.user, read=False).order_by('-datetime')[steps:steps+amount] + if len(notifications) == 0: + return HttpResponse("nothing") + else: + amountGotten = len(notifications) context['notifications'] = notifications else: #go to login page return HttpResponse('teste') html = render_to_string("notifications.html", context) - return HttpResponse(html) + data = {} + data['html'] = html + data['amountGotten'] = amountGotten + return JsonResponse(data) def guest (request): context = { -- libgit2 0.21.2