notifications now get cleared when visiting a page with a new comment or a revision page with unread notification, unread comments get highlighted
--- a/src/iconolab/templates/iconolab/detail_annotation.html Fri Aug 12 10:29:22 2016 +0200
+++ b/src/iconolab/templates/iconolab/detail_annotation.html Mon Aug 08 16:30:12 2016 +0200
@@ -77,7 +77,7 @@
<h4 id="annotation-comments-header">Commentaires</h4>
<ul class="list-group annotation-comments" id="comments">
{% for comment in comments %}
- <li class="list-group-item" id="c{{ comment.id }}" style="margin-left:calc({{ comment.level }}*5px);">
+ <li class="list-group-item {% if comment.id in notifications_comments_ids %}list-group-item-warning{% endif %}" id="c{{ comment.id }}" style="margin-left:calc({{ comment.level }}*5px);">
<p id="c{{comment.id}}-content" class="comment-content">{{ comment.comment }}</p>
<hr class="comment-separator">
{% if comment.allow_thread and user.is_authenticated %}<div class="pull-right"><a class="btn btn-default btn-xs reply-to-btn" id="reply-to-{{comment.id}}" class="comment-reply-link">Répondre</a></div>{% endif %}
--- a/src/iconolab/templates/partials/header.html Fri Aug 12 10:29:22 2016 +0200
+++ b/src/iconolab/templates/partials/header.html Mon Aug 08 16:30:12 2016 +0200
@@ -22,7 +22,10 @@
<ul class="nav navbar-nav navbar-right">
{% if request.user.is_authenticated %}
{% notifications_unread as unread_count %}
- <li><a href="{% url 'user_home' request.user.id %}">{{user.username}}: Mon espace <span class="badge {% if unread_count %}badge-error{% endif %}">{{ unread_count }}</span></a></li>
+ <li><a href="{% url 'user_home' request.user.id %}">
+ {{user.username}}: Mon espace <span class="badge {% if unread_count %}badge-warning{% endif %}">
+ {{ unread_count }} <i class="fa fa-envelope-o" aria-hidden="true"></i> </span>
+ </a></li>
<li><a href="{% url 'account:logout' %}">Se déconnecter</a></li>
{% else %}
<li><a href="{% url 'account:register' %}">Créer un compte</a></li>
--- a/src/iconolab/views/iconolab.py Fri Aug 12 10:29:22 2016 +0200
+++ b/src/iconolab/views/iconolab.py Mon Aug 08 16:30:12 2016 +0200
@@ -259,6 +259,20 @@
comments_list = paginator.page(paginator.num_pages)
context["comments"] = comments_list
+ if request.user.is_authenticated():
+ user_comment_notifications = Notification.objects.filter(
+ recipient=request.user,
+ action_object_content_type__app_label="iconolab",
+ action_object_content_type__model="iconolabcomment",
+ target_content_type__app_label="iconolab",
+ target_content_type__model="annotation",
+ target_object_id=annotation.id
+ ).unread()
+ context["notifications_comments_ids"] = [int(val) for val in user_comment_notifications.values_list("action_object_object_id", flat=True)]
+ comment_list_ids = [comment.id for comment in context["comments"] ]
+ for notification in user_comment_notifications.all():
+ if int(notification.action_object_object_id) in comment_list_ids:
+ notification.mark_as_read()
image.stats.views_count += 1
image.stats.save()
@@ -384,6 +398,19 @@
context['revision'] = revision
context['tags_data'] = revision.get_tags_json()
context['comment'] = revision.creation_comment.first()
+ if request.user.is_authenticated() and annotation.author == request.user:
+ notified_revision = Notification.objects.filter(
+ recipient=request.user,
+ action_object_content_type__app_label="iconolab",
+ action_object_content_type__model="annotationrevision",
+ action_object_object_id=revision.id,
+ target_content_type__app_label="iconolab",
+ target_content_type__model="annotation",
+ target_object_id=annotation.id
+ ).unread()
+ if notified_revision:
+ notified_revision.first().mark_as_read()
+ context["notified_revision"] = True
return render(request, 'iconolab/detail_revision.html', context)