Repository: django-oscar/django-oscar

Issue:
Is notifications alert is broken?
Is notifications alert is broken?

Unread notifications should be alerted on page header (if I see right in `nav_accounts.html`, `{% if num_unread_notifications > 0 %} ...`)

But it's not shown.

And unread notifications doesn't mark in account notification list.

I think it's a bug


Discussion:
I see what is working - if user has a unread messages then Account link follow to notifications page, not main account. It's right,

What is NOT working - notification count is not shown in nav bar.

And one annoying feature - if you go to notification page then all unread messages will mark as read immediately. I think this is wrong. What this [line](https://github.com/django-oscar/django-oscar/blob/master/src/oscar/apps/customer/notifications/views.py#L43) is used for?
  

Resolving patch:
diff --git a/src/oscar/apps/customer/notifications/views.py b/src/oscar/apps/customer/notifications/views.py
--- a/src/oscar/apps/customer/notifications/views.py
+++ b/src/oscar/apps/customer/notifications/views.py
@@ -32,20 +32,9 @@ class InboxView(NotificationListView):
     list_type = 'inbox'
 
     def get_queryset(self):
-        qs = self.model._default_manager.filter(
+        return self.model._default_manager.filter(
             recipient=self.request.user,
             location=self.model.INBOX)
-        # Mark unread notifications so they can be rendered differently...
-        for obj in qs:
-            if not obj.is_read:
-                setattr(obj, 'is_new', True)
-        # ...but then mark everything as read.
-        self.mark_as_read(qs)
-        return qs
-
-    def mark_as_read(self, queryset):
-        unread = queryset.filter(date_read=None)
-        unread.update(date_read=now())
 
 
 class ArchiveView(NotificationListView):
@@ -63,6 +52,13 @@ class DetailView(PageTitleMixin, generic.DetailView):
     context_object_name = 'notification'
     active_tab = 'notifications'
 
+    def get_object(self, queryset=None):
+        obj = super(DetailView, self).get_object()
+        if not obj.date_read:
+            obj.date_read = now()
+            obj.save()
+        return obj
+
     def get_page_title(self):
         """Append subject to page title"""
         title = strip_tags(self.object.subject)


Test patch:
diff --git a/tests/functional/customer/test_notification.py b/tests/functional/customer/test_notification.py
--- a/tests/functional/customer/test_notification.py
+++ b/tests/functional/customer/test_notification.py
@@ -1,6 +1,9 @@
 from oscar.test.testcases import WebTestCase
 from oscar.apps.customer.notifications import services
 from oscar.test.factories import UserFactory
+from django.utils.six.moves import http_client
+from django.core.urlresolvers import reverse
+from oscar.apps.customer.models import Notification
 
 
 class TestAUserWithUnreadNotifications(WebTestCase):
@@ -11,5 +14,18 @@ def setUp(self):
 
     def test_can_see_them_in_page_header(self):
         homepage = self.app.get('/', user=self.user)
-        self.assertTrue('num_unread_notifications' in homepage.context)
         self.assertEqual(1, homepage.context['num_unread_notifications'])
+
+    def test_notification_list_view_shows_user_notifications(self):
+        response = self.app.get(reverse('customer:notifications-inbox'), user=self.user)
+        self.assertEqual(1, len(response.context['notifications']))
+        self.assertEqual(False, response.context['notifications'][0].is_read)
+
+    def test_notification_marked_as_read(self):
+        n = Notification.objects.first()
+        path = reverse('customer:notifications-detail', kwargs={'pk': n.id})
+        response = self.app.get(path, user=self.user)
+        # notification should be marked as read
+        self.assertEqual(http_client.OK, response.status_code)
+        n.refresh_from_db()
+        self.assertTrue(n.is_read)