fix merge

This commit is contained in:
Samuel Spencer 2015-12-12 09:41:12 +00:00
commit 0aa46f7567
8 changed files with 70 additions and 35 deletions

View file

@ -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::
<script src="{% static 'notifications/notify.js' %}" type="text/javascript"></script>
{% register_notify_callbacks callbacks='fill_notification_list,fill_notification_badge' %}
@ -282,23 +282,23 @@ How to use:
#. ``callbacks`` (default ``<empty string>``) - 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 ``<span>`` element that will be created to show the unread count.
#. ``classes`` (default ``<empty string>``) - A string used to populate the ``class`` attribute of the above element.
1. ``badge_id`` (default ``live_notify_badge``) - The ``id`` attribute for the ``<span>`` element that will be created to show the unread count.
#. ``classes`` (default ``<empty string>``) - 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 ``<ul>`` element that will be created to insert the list of notifications into.
#. ``classes`` (default ``<empty string>``) - A string used to populate the ``class`` attribute of the above element.
1. ``list_id`` (default ``live_notify_list``) - The ``id`` attribute for the ``<ul>`` element that will be created to insert the list of notifications into.
#. ``classes`` (default ``<empty string>``) - 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::

View file

@ -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()

View file

@ -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 + "<li>"+item.object+" "+item.verb+" "+item.subject+" at " +item.timestamp + "</li>";
console.log(item)
menu.innerHTML = menu.innerHTML + "<li>"+item.actor+" "+item.verb+" "+item.target+" at " +item.timestamp + "</li>";
}
}
}
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++;

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

@ -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 = "<script>"+definitions
for callback in callbacks.split(','):
script += "register_notifier("+callback+");"
@ -62,7 +63,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

@ -2,7 +2,7 @@
<script src="{% static 'notifications/notify.js' %}" type="text/javascript"></script>
<script src="{% static 'notifications/live-test.js' %}" type="text/javascript"></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: <span id='live_notify_badge'></span>

View file

@ -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)

View file

@ -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)