diff --git a/README.rst b/README.rst
index d376519..7922c16 100644
--- a/README.rst
+++ b/README.rst
@@ -250,11 +250,11 @@ for updating specific fields within a django template.
There are two possible API calls that can be made:
- 1. ``api/unread_count/`` that returns a javascript object with 1 key: ``unread_count`` eg::
+ 1. ``api/unread_count/`` that returns a javascript object with 1 key: ``unread_count`` eg::
{"unread_count":1}
- #. ``api/unread_list/`` that returns a javascript object with 2 keys: `unread_count` and `unread_list` eg::
+ #. ``api/unread_list/`` that returns a javascript object with 2 keys: `unread_count` and `unread_list` eg::
{
"unread_count":1,
@@ -267,8 +267,8 @@ There are two possible API calls that can be made:
How to use:
-----------
- 1. Put ``{% load notifications_tags %}`` in the template before you actually use notification tags.
- 2. In the area where you are loading javascript resources add the following tags in the order below::
+ 1. Put ``{% load notifications_tags %}`` in the template before you actually use notification tags.
+ 2. In the area where you are loading javascript resources add the following tags in the order below::
{% register_notify_callbacks callbacks='fill_notification_list,fill_notification_badge' %}
@@ -282,23 +282,23 @@ How to use:
#. ``callbacks`` (default ````) - A comma-separated list of javascript functions to call each period.
#. ``api_url_name`` (default ``list``) - The name of the API to call (this can be either ``list`` or ``count``).
- 3. To insert a live-updating unread count, use the following template::
+ 3. To insert a live-updating unread count, use the following template::
{% live_notify_badge %}
``live_notify_badge`` takes the following arguments:
- 1. ``badge_id`` (default ``live_notify_badge``) - The ``id`` attribute for the ```` element that will be created to show the unread count.
- #. ``classes`` (default ````) - A string used to populate the ``class`` attribute of the above element.
+ 1. ``badge_id`` (default ``live_notify_badge``) - The ``id`` attribute for the ```` element that will be created to show the unread count.
+ #. ``classes`` (default ````) - A string used to populate the ``class`` attribute of the above element.
- 4. To insert a live-updating unread count, use the following template::
+ 4. To insert a live-updating unread count, use the following template::
{% live_notify_list %}
-
+
``live_notify_list`` takes the following arguments:
- 1. ``list_id`` (default ``live_notify_list``) - The ``id`` attribute for the ```` element that will be created to insert the list of notifications into.
- #. ``classes`` (default ````) - A string used to populate the ``class`` attribute of the above element.
+ 1. ``list_id`` (default ``live_notify_list``) - The ``id`` attribute for the ```` element that will be created to insert the list of notifications into.
+ #. ``classes`` (default ````) - A string used to populate the ``class`` attribute of the above element.
Using the live-updater with bootstrap
-------------------------------------
@@ -320,7 +320,7 @@ While the live notifier for unread counts should suit most use cases, users may
unread notifications are shown.
The ``callbacks`` argument of the ``register_notify_callbacks`` dictates which javascript functions are called when
-the unread api call is made.
+the unread api call is made.
To add a custom javascript callback, simply add this to the list, like so::
diff --git a/notifications/__init__.py b/notifications/__init__.py
index c73842c..0631da7 100644
--- a/notifications/__init__.py
+++ b/notifications/__init__.py
@@ -8,3 +8,25 @@ try:
urls = (urlpatterns, 'notifications', 'notifications')
except ImportError:
pass
+
+__version_info__ = {
+ 'major': 0,
+ 'minor': 8,
+ 'micro': 0,
+ 'releaselevel': 'final',
+ 'serial': 0
+}
+
+
+def get_version(release_level=True):
+ """
+ Return the formatted version information
+ """
+ vers = ["%(major)i.%(minor)i.%(micro)i" % __version_info__]
+ if release_level and __version_info__['releaselevel'] != 'final':
+ vers.append('%(releaselevel)s%(serial)i' % __version_info__)
+ return ''.join(vers)
+
+
+__version__ = get_version()
+
diff --git a/notifications/static/notifications/notify.js b/notifications/static/notifications/notify.js
index e785549..a660f01 100644
--- a/notifications/static/notifications/notify.js
+++ b/notifications/static/notifications/notify.js
@@ -1,6 +1,7 @@
var notify_badge_id;
var notify_menu_id;
var notify_api_url;
+var notify_fetch_count;
var notify_unread_url;
var notify_mark_all_unread_url;
var notify_refresh_period = 15000;
@@ -20,21 +21,21 @@ 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 + "- "+item.object+" "+item.verb+" "+item.subject+" at " +item.timestamp + "
";
+ console.log(item)
+ menu.innerHTML = menu.innerHTML + "- "+item.actor+" "+item.verb+" "+item.target+" at " +item.timestamp + "
";
}
}
}
function register_notifier(func) {
registered_functions.push(func);
- console.log(registered_functions)
}
function fetch_api_data() {
if (registered_functions.length > 0) {
//only fetch data if a function is setup
var r = new XMLHttpRequest();
- r.open("GET", notify_api_url, true);
+ r.open("GET", notify_api_url+'?max='+notify_fetch_count, true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) {
consecutive_misfires++;
diff --git a/notifications/templates/notifications/test_tags.html b/notifications/templates/notifications/test_tags.html
index 6ace50b..eab7bda 100644
--- a/notifications/templates/notifications/test_tags.html
+++ b/notifications/templates/notifications/test_tags.html
@@ -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 }}
diff --git a/notifications/templatetags/notifications_tags.py b/notifications/templatetags/notifications_tags.py
index e001623..054bfd0 100644
--- a/notifications/templatetags/notifications_tags.py
+++ b/notifications/templatetags/notifications_tags.py
@@ -15,7 +15,7 @@ def notifications_unread(context):
# Requires vanilla-js framework - http://vanilla-js.com/
@register.simple_tag
-def register_notify_callbacks(badge_id='live_notify_badge',menu_id='live_notify_list',refresh_period=15,callbacks="",api_name='list',to_fetch=5):
+def register_notify_callbacks(badge_id='live_notify_badge',menu_id='live_notify_list',refresh_period=15,callbacks="",api_name='list',fetch=5):
refresh_period=int(refresh_period)*1000
if api_name=='list':
@@ -29,18 +29,19 @@ def register_notify_callbacks(badge_id='live_notify_badge',menu_id='live_notify_
notify_badge_id='{badge_id}';
notify_menu_id='{menu_id}';
notify_api_url='{api_url}';
+ notify_fetch_count='{fetch_count}';
notify_unread_url='{unread_url}';
notify_mark_all_unread_url='{mark_all_unread_url}';
- notify_to_fetch='{to_fetch}';
- 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'),
- to_fetch=to_fetch,
- )
-
+ 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'),
+ fetch_count=fetch
+ )
+
script = "
-{% register_notify_callbacks callbacks='fill_notification_list,fill_notification_badge' to_fetch=20 refresh_period=5 %}
+{% register_notify_callbacks callbacks='fill_notification_list,fill_notification_badge' fetch=20 refresh_period=5 %}
There are this many notifications pending:
diff --git a/notifications/tests/views.py b/notifications/tests/views.py
index 1f1d1b7..7af9ea5 100644
--- a/notifications/tests/views.py
+++ b/notifications/tests/views.py
@@ -6,7 +6,7 @@ from notifications import notify
import random
def live_tester(request):
- notify.send(request.user, recipient=request.user, verb='you loaded the page')
+ notify.send(sender=request.user, recipient=request.user, verb='you loaded the page')
data = {
'unread_count': request.user.notifications.unread().count(),
@@ -23,5 +23,5 @@ def make_notification(request):
'testing the app',
])
- notify.send(request.user, recipient=request.user, verb='you asked for a notification - you are '+the_notification)
+ notify.send(sender=request.user, recipient=request.user, verb='you asked for a notification - you are '+the_notification)
diff --git a/notifications/views.py b/notifications/views.py
index 21ddd38..de4c7ac 100644
--- a/notifications/views.py
+++ b/notifications/views.py
@@ -131,14 +131,25 @@ 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 = 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
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_count':request.user.notifications.unread().count(),
+ 'unread_list':unread_list
}
return JsonResponse(data)