Repository: danidee10/django-notifs (language: python)

Issue:
Questionnable usefulness of context processor
The context processor in `notifivcations.notifications.notifications`, besides being named interestingly, is of questionnable use in my opinion.

As the current user is injected into template context by default, except if a project diverts from the stnadard behaviour of having `RequestContext`, injecting one attribute of the user again is not really useful. Templates should simply use `user.notifications`.


Discussion / hints:

Fix patch:
diff --git a/notifications/notifications.py b/notifications/notifications.py
deleted file mode 100644
index faea859..0000000
--- a/notifications/notifications.py
+++ /dev/null
@@ -1,13 +0,0 @@
-"""
-Context Processor
-
-To include the notifications varialbe in all templates.
-"""
-
-
-def notifications(request):
-    """Make notifications available in all templates."""
-    if not request.user.is_authenticated:
-        return {}
-
-    return {'notifications': request.user.notifications}
diff --git a/notifications/templates/notifications/notification_list.html b/notifications/templates/notifications/notification_list.html
index ef549b5..8771c32 100644
--- a/notifications/templates/notifications/notification_list.html
+++ b/notifications/templates/notifications/notification_list.html
@@ -1,5 +1,5 @@
-{% for notification in notifications.all %}
+{% for notification in user.notifications.all %}
 
     <p>{{ notification.source }}</p>
 
-{% endfor %}
\ No newline at end of file
+{% endfor %}


Test patch:
diff --git a/notifications/tests/tests.py b/notifications/tests/tests.py
index c97cfe1..513edd0 100644
--- a/notifications/tests/tests.py
+++ b/notifications/tests/tests.py
@@ -8,7 +8,6 @@
 from .. import NotificationError
 from ..models import Notification
 from ..tasks import send_notification
-from ..notifications import notifications
 
 
 class GeneralTestCase(TestCase):
@@ -232,24 +231,6 @@ def test_string_representation(self):
         )
         self.assertEqual(str(notification), 'Admin was  notified')
 
-    def test_context_processor(self):
-        """Test the 'notifications context processor."""
-        Notification.objects.create(
-            source=self.user2, source_display_name='User 2',
-            recipient=self.user1, action='Notified',
-            category='Admin notification', obj=1, url='http://example.com',
-            is_read=False
-        )
-
-        request = RequestFactory()
-        request.user = AnonymousUser()
-        self.assertEqual(notifications(request), {})
-
-        # 'authenticate' the request
-        request.user = self.user1
-        notifications_count = notifications(request)['notifications'].count()
-        self.assertEqual(notifications_count, 1)
-
 
 class JSONFieldTestCase(TestCase):
     """Test the Custom JSONField."""