Commit 8a9b8804f60634a4a963777ce27464c693e418a6

Authored by fbormann
1 parent 446a2326

bug finished, I've added support for odd numbers and updates are correct

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 @@ -91,10 +91,15 @@ This functions get the next 5 notifications from the user given a "step"(an amou
91 function getNotifications(step){ 91 function getNotifications(step){
92 $.get('/getNotifications', 92 $.get('/getNotifications',
93 {'steps':step, 'amount': 5}, function(data){ 93 {'steps':step, 'amount': 5}, function(data){
94 - $("#notification-dropdown").append(data);  
95 - $('#notification-see-more').remove();  
96 - var seemore = '<li><a onclick="getNotifications('+(step+5)+')"> <div id="notification-see-more" class="list-group-item"> <div class="row-content"><p class="list-group-item-text">See More</p> </div> </a></li>';  
97 - $("#notification-dropdown").append(seemore);  
98 - $("#notification-count").text(step+5); 94 + if(data == "nothing"){
  95 + console.log("No notifications");
  96 + }else{
  97 + $("#notification-dropdown").append(data['html']);
  98 + $('#notification-see-more').remove();
  99 + var seemore = '<li><a onclick="getNotifications('+(step+data['amountGotten'])+')"> <div id="notification-see-more" class="list-group-item"> <div class="row-content"><p class="list-group-item-text">See More</p> </div> </a></li>';
  100 + $("#notification-dropdown").append(seemore);
  101 + $("#notification-count").text(step+data['amountGotten']);
  102 + }
  103 +
99 }); 104 });
100 } 105 }
core/templates/notifications.html
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 <div class="least-content "> {{ notification.datetime|timesince }} </div> 14 <div class="least-content "> {{ notification.datetime|timesince }} </div>
15 </div> 15 </div>
16 <div class="row-content"> 16 <div class="row-content">
17 - <p class="list-group-item-text">{{ notification.message }}</p> 17 + <p class="list-group-item-text">{{notification.actor.username}} {{ notification.message }}</p>
18 </div> 18 </div>
19 </div> 19 </div>
20 </a> 20 </a>
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 30
31 <div class="least-content pull-right">{{ notification.datetime|timesince }}</div> 31 <div class="least-content pull-right">{{ notification.datetime|timesince }}</div>
32 32
33 - <p class="list-group-item-text">{{ notification.message }}</p> 33 + <p class="list-group-item-text">{{notification.actor.username}} {{ notification.message }}</p>
34 </div> 34 </div>
35 </a> 35 </a>
36 </li> 36 </li>
@@ -101,17 +101,24 @@ def processNotification(self, notificationId): @@ -101,17 +101,24 @@ def processNotification(self, notificationId):
101 def getNotifications(request): 101 def getNotifications(request):
102 context = {} 102 context = {}
103 if request.user.is_authenticated: 103 if request.user.is_authenticated:
104 - 104 + amountGotten = 0 #amountOfNotifications actually received
105 steps = int(request.GET['steps']) 105 steps = int(request.GET['steps'])
106 amount = int(request.GET['amount']) 106 amount = int(request.GET['amount'])
107 notifications = Notification.objects.filter(user= request.user, read=False).order_by('-datetime')[steps:steps+amount] 107 notifications = Notification.objects.filter(user= request.user, read=False).order_by('-datetime')[steps:steps+amount]
  108 + if len(notifications) == 0:
  109 + return HttpResponse("nothing")
  110 + else:
  111 + amountGotten = len(notifications)
108 context['notifications'] = notifications 112 context['notifications'] = notifications
109 else: #go to login page 113 else: #go to login page
110 return HttpResponse('teste') 114 return HttpResponse('teste')
111 115
112 116
113 html = render_to_string("notifications.html", context) 117 html = render_to_string("notifications.html", context)
114 - return HttpResponse(html) 118 + data = {}
  119 + data['html'] = html
  120 + data['amountGotten'] = amountGotten
  121 + return JsonResponse(data)
115 122
116 def guest (request): 123 def guest (request):
117 context = { 124 context = {