fix attempt to fix my mess

This commit is contained in:
theodore.therone@gmail.com 2015-11-11 11:04:12 +00:00
parent c8b27d3dd9
commit b2b4fac254
4 changed files with 19 additions and 8 deletions

View file

@ -20,7 +20,7 @@ function fill_notification_list(data) {
menu.innerHTML = "";
for (var i=0; i < data.unread_list.length; i++) {
var item = data.unread_list[i];
menu.innerHTML = menu.innerHTML + "<li>"+item.object+" "+item.verb+" "+item.subject+"</li>";
menu.innerHTML = menu.innerHTML + "<li>"+item.actor+" "+item.verb+" "+item.target+"</li>";
}
}
}

View file

@ -1,6 +1,6 @@
{% load notifications_tags %}
{% register_notify_callbacks callbacks='fill_aristotle_notification_menu,fill_notification_badge' %}
{% register_notify_callbacks callbacks='fill_notification_menu,fill_notification_badge' %}
{% notifications_unread as unread %}
{{ unread }}

View file

@ -32,7 +32,7 @@ def register_notify_callbacks(badge_id='live_notify_badge',menu_id='live_notify_
notify_unread_url='{unread_url}';
notify_mark_all_unread_url='{mark_all_unread_url}';
notify_refresh_period={refresh};""".format(badge_id=badge_id,menu_id=menu_id,refresh=refresh_period,api_url=api_url,unread_url=reverse('notifications:unread'),mark_all_unread_url=reverse('notifications:mark_all_as_read'))
script = "<script>"+definitions
for callback in callbacks.split(','):
script += "register_notifier("+callback+");"
@ -54,7 +54,7 @@ def live_notify_list(list_id='live_notify_list',classes=""):
html="<ul id='{list_id}' class='{classes}'></ul>".format(list_id=list_id,classes=classes)
return html
def user_context(context):
def user_context(context):
if 'user' not in context:
return None

View file

@ -19,7 +19,7 @@ else:
from django.http import HttpResponse
def date_handler(obj):
return obj.isoformat() if hasattr(obj, 'isoformat') else obj
def JsonResponse(data):
return HttpResponse(json.dumps(data, default=date_handler), content_type="application/json")
@ -125,18 +125,29 @@ def live_unread_notification_count(request):
return JsonResponse(data)
def live_unread_notification_list(request):
try:
num_to_fetch = request.GET.get('max',5) #If they don't specify, make it 5.
num_to_fetch = int(num_to_fetch)
num_to_fetch = max(1,num_to_fetch) # if num_to_fetch is negative, force at least one fetched notifications
num_to_fetch = min(num_to_fetch,100) # put a sane ceiling on the number retrievable
num_to_fetch = min(num_to_fetch,100) # put a sane ceiling on the number retrievable
except ValueError:
num_to_fetch = 5 # If casting to an int fails, just make it 5.
unread_list = []
for n in request.user.notifications.unread()[0:num_to_fetch]:
struct = model_to_dict(n)
if n.actor:
struct['actor'] = str(n.actor)
if n.target:
struct['target'] = str(n.target)
if n.action_object:
struct['action_object'] = str(n.action_object)
unread_list.append(struct)
data = {
'unread_count':request.user.notifications.unread().count(),
'unread_list':[model_to_dict(n) for n in request.user.notifications.unread()[0:num_to_fetch]]
'unread_list':unread_list
}
return JsonResponse(data)