Pagination for notifications and changing notification badge color (yellow) to match new comment highlight color
--- a/src/iconolab/templates/iconolab/user_home.html Mon Aug 08 16:30:12 2016 +0200
+++ b/src/iconolab/templates/iconolab/user_home.html Mon Aug 08 18:24:27 2016 +0200
@@ -16,13 +16,13 @@
<div class="panel panel-default" style="padding-left: 10px; padding-right: 10px;">
{% if profile_user == request.user %}
{% notifications_unread as unread_count %}
- <h4><span class="badge notif-badge {% if unread_count %}badge-error{% endif %}">{{unread_count}}</span> Notifications non lues
+ <h4><span class="badge notif-badge {% if unread_count %}badge-warning{% endif %}">{{unread_count}} <i class="fa fa-envelope-o" aria-hidden="true"></i></span> Notifications non lues
<a href="{% url 'user_notifications' %}" class="btn btn-default btn-xs">Voir toutes mes notifications</a>
- <a href="{% url 'user_home' profile_user.id %}?clear_notifications=True" class="btn btn-default btn-xs">Tout marquer comme lu</a>
+ {% if unread_count %}<a href="{% url 'user_home' profile_user.id %}?clear_notifications=True" class="btn btn-default btn-xs">Tout marquer comme lu</a>{% endif %}
</h4>
<div class="row">
<div class="col-md-12">
- {% if notifications %}
+ {% if unread_count %}
<ul class="list-group">
{% for notification in notifications.unread %}
<a
--- a/src/iconolab/templates/iconolab/user_notifications.html Mon Aug 08 16:30:12 2016 +0200
+++ b/src/iconolab/templates/iconolab/user_notifications.html Mon Aug 08 18:24:27 2016 +0200
@@ -33,6 +33,30 @@
</a>
{% endfor %}
</ul>
+
+ {% if notifications.has_previous or notifications.has_next %}
+ <ul class="pagination pull-right">
+ {% if notifications.has_previous %}
+ <li>
+ <a href="{% url 'user_notifications' %}?page={{notifications.previous_page_number}}" aria-label="Previous">
+ <span aria-hidden="true">«</span>
+ </a>
+ </li>
+ {% endif %}
+ {% for page in notifications.paginator.page_range %}
+ <li id="page-link-{{page}}" class="pagination-link {% if page == notifications.number %}active{% endif %}">
+ <a {% if page != notifications.number %}href="{% url 'user_notifications' %}?page={{page}}"{% endif %}>{{page}}</a>
+ </li>
+ {% endfor %}
+ {% if notifications.has_next %}
+ <li>
+ <a href="{% url 'user_notifications' %}?page={{notifications.next_page_number}}" aria-label="Next">
+ <span aria-hidden="true">»</span>
+ </a>
+ </li>
+ {% endif %}
+ </ul>
+ {% endif %}
{% endif %}
</div>
</div>
--- a/src/iconolab/views/iconolab.py Mon Aug 08 16:30:12 2016 +0200
+++ b/src/iconolab/views/iconolab.py Mon Aug 08 18:24:27 2016 +0200
@@ -64,8 +64,15 @@
context = {}
notifications = Notification.objects.filter(recipient=request.user)
context["notifications_unread_ids"] = notifications.unread().values_list("id", flat=True)
- notifications.mark_all_as_read()
- context["notifications"] = notifications
+ page = request.GET.get("page", 1)
+ paginator = Paginator(notifications, 50)
+ try:
+ notifications_list = paginator.page(page)
+ except PageNotAnInteger:
+ notifications_list = paginator.page(1)
+ except EmptyPage:
+ notifications_list = paginator.page(paginator.num_pages)
+ context["notifications"] = notifications_list
return render(request, 'iconolab/user_notifications.html', context)