notifications.html 2.64 KB
Newer Older
1 2 3
<%! from django.core.urlresolvers import reverse %>

<%
Rocky Duan committed
4 5
def url_for_thread(discussion_id, thread_id):
  return reverse('django_comment_client.forum.views.single_thread', args=[course.id, discussion_id, thread_id])
6 7 8
%>

<% 
Rocky Duan committed
9 10
def url_for_comment(discussion_id, thread_id, comment_id):
  return url_for_thread(discussion_id, thread_id) + "#" + comment_id
11 12 13 14 15 16 17 18 19 20 21 22
%>

<%
def url_for_discussion(discussion_id):
  return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course.id, discussion_id])
%>

<% 
def discussion_title(discussion_id):
  return get_discussion_title(discussion_id=discussion_id)
%>

23 24 25 26 27
<%
def url_for_user(user_id): #TODO
  return "javascript:void(0)"
%>

28 29 30 31 32 33 34

<div class="notifications">
  % for notification in notifications:
    ${render_notification(notification)}
  % endfor
</div>

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
<%def name="render_user_link(notification)">
  <% info = notification['info'] %>
  % if notification.get('actor_id', None):
    <a href="${url_for_user(notification['actor_id'])}">${info['actor_username']}</a>
  % else:
    Anonymous
  % endif
</%def>

<%def name="render_thread_link(notification)">
  <% info = notification['info'] %>
  <a href="${url_for_thread(info['commentable_id'], info['thread_id'])}">${info['thread_title']}</a>
</%def>

<%def name="render_comment_link(notification)">
  <% info = notification['info'] %>
  <a href="${url_for_comment(info['commentable_id'], info['thread_id'], info['comment_id'])}">comment</a>
</%def>

<%def name="render_discussion_link(notification)">
  <% info = notification['info'] %>
  <a href="${url_for_discussion(info['commentable_id'])}">${discussion_title(info['commentable_id'])}</a>
</%def>

59 60 61
<%def name="render_notification(notification)">
  <div class="notification">
    % if notification['notification_type'] == 'post_reply':
62 63
      ${render_user_link(notification)} posted a ${render_comment_link(notification)} 
      to the thread ${render_thread_link(notification)} in discussion ${render_discussion_link(notification)}
64
    % elif notification['notification_type'] == 'post_topic':
65 66 67 68 69 70 71 72 73 74 75
      ${render_user_link(notification)} posted a new thread ${render_thread_link(notification)}
      in discussion ${render_discussion_link(notification)}
    % elif notification['notification_type'] == 'at_user':
      ${render_user(info)} mentioned you in 
      % if notification['info']['content_type'] == 'thread':
        the thread ${render_thread_link(notification)}
        in discussion ${render_discussion_link(notification)}
      % else:
        ${render_comment_link(notification)} 
        to the thread ${render_thread_link(notification)} in discussion ${render_discussion_link(notification)}
      % endif
76 77 78 79
    % endif
  </div>

</%def>