Restore button to clear notifications.
authorAlexandre Segura <mex.zktk@gmail.com>
Tue, 21 Mar 2017 11:29:54 +0100
changeset 454 94334e3761ef
parent 453 8bf4f5457d8b
child 455 aff03a86c471
Restore button to clear notifications.
src/iconolab/templates/iconolab/user_notifications.html
src/iconolab/views/userpages.py
--- a/src/iconolab/templates/iconolab/user_notifications.html	Mon Mar 20 14:23:31 2017 +0100
+++ b/src/iconolab/templates/iconolab/user_notifications.html	Tue Mar 21 11:29:54 2017 +0100
@@ -1,15 +1,21 @@
 {% extends 'iconolab/user_base.html' %}
 
 {% load staticfiles %}
-
 {% load thumbnail %}
-
 {% load iconolab_tags %}
-
 {% load notifications_tags %}
 
 {% block user_content %}
-  <h2>Mes notifications</h2>
+
+  {% notifications_unread as unread_count %}
+  <h2>
+    Mes notifications
+    {% if unread_count %} <a class="btn btn-success pull-right" href="{% url 'user_notifications' %}?clear_notifications">
+    <i class="fa fa-check"></i> Tout marquer comme lu</a>
+    {% endif %}
+  </h2>
+  <hr>
+
   {% if notifications %}
     <ul class="list-group">
     {% for notification in notifications %}
--- a/src/iconolab/views/userpages.py	Mon Mar 20 14:23:31 2017 +0100
+++ b/src/iconolab/views/userpages.py	Tue Mar 21 11:29:54 2017 +0100
@@ -44,13 +44,6 @@
     def get(self, request, *args, **kwargs):
         self.object = self.get_object()
         context = self.get_context_data()
-
-        if request.user.is_authenticated() and self.object == request.user:
-            if request.GET.get('clear_notifications', False):
-                Notification.objects.filter(recipient=request.user).mark_all_as_read()
-            logger.debug(Notification.objects.filter(recipient=request.user))
-            context['notifications'] = Notification.objects.filter(recipient=request.user)
-
         return render(request, 'iconolab/user_home.html', context)
 
 class UserNotificationsView(View):
@@ -60,6 +53,10 @@
     def get(self, request, *args, **kwargs):
         context = {}
         notifications = Notification.objects.filter(recipient=request.user)
+
+        if request.user.is_authenticated() and 'clear_notifications' in request.GET:
+            Notification.objects.filter(recipient=request.user).mark_all_as_read()
+
         context['notifications_unread_ids'] = notifications.unread().values_list('id', flat=True)
         context['profile_user'] = request.user
         page = request.GET.get('page', 1)