From 2c4aaab4357de944904ccb5bca106180fd9f0905 Mon Sep 17 00:00:00 2001 From: echoduck Date: Oct 26 2018 21:01:58 +0000 Subject: [PATCH 1/2] Added packets sent counter to sidebar --- diff --git a/happinesspackets/messaging/context_processors.py b/happinesspackets/messaging/context_processors.py new file mode 100644 index 0000000..1c4672e --- /dev/null +++ b/happinesspackets/messaging/context_processors.py @@ -0,0 +1,5 @@ +from .models import Message + +def packets_sent_processor(request): + packets_sent = Message.objects.filter(status="sent").count() + return {'packets_sent': packets_sent} diff --git a/happinesspackets/settings/base.py b/happinesspackets/settings/base.py index db439e9..249badd 100644 --- a/happinesspackets/settings/base.py +++ b/happinesspackets/settings/base.py @@ -92,6 +92,7 @@ TEMPLATES = [ "django.template.context_processors.static", "django.template.context_processors.tz", "django.contrib.messages.context_processors.messages", + "happinesspackets.messaging.context_processors.packets_sent_processor", ], 'loaders': [ 'django.template.loaders.filesystem.Loader', diff --git a/templates/base.html b/templates/base.html index 92287b5..8752223 100644 --- a/templates/base.html +++ b/templates/base.html @@ -53,6 +53,7 @@ {% endif %} +

Packets sent: {{ packets_sent }}

From 1dcb6663285ad27ce191ce9b38ff34d9ae5be8a7 Mon Sep 17 00:00:00 2001 From: echoduck Date: Oct 26 2018 21:01:58 +0000 Subject: [PATCH 2/2] Changed styling to be consistent with the rest of the sidebar, added tests, and added read messages to the counter. --- diff --git a/happinesspackets/messaging/context_processors.py b/happinesspackets/messaging/context_processors.py index 1c4672e..29eff6a 100644 --- a/happinesspackets/messaging/context_processors.py +++ b/happinesspackets/messaging/context_processors.py @@ -1,5 +1,5 @@ from .models import Message def packets_sent_processor(request): - packets_sent = Message.objects.filter(status="sent").count() + packets_sent = Message.objects.exclude(status="pending_sender_confirmation").count() return {'packets_sent': packets_sent} diff --git a/happinesspackets/messaging/tests/test_views.py b/happinesspackets/messaging/tests/test_views.py index e5db934..e104640 100644 --- a/happinesspackets/messaging/tests/test_views.py +++ b/happinesspackets/messaging/tests/test_views.py @@ -11,6 +11,25 @@ from .test_models import MessageModelFactory, BlacklistedEmailFactory from ..models import Message, BLACKLIST_HMAC_SALT, BlacklistedEmail +class MessageCounterTest(TestCase): + url = reverse('messaging:start') + + def test_message_sent_included(self): + msg = MessageModelFactory(status="sent") + response = self.client.get(self.url) + self.assertContains(response,"Packets sent: 1") + + def test_message_read_included(self): + msg = MessageModelFactory(status="read") + response = self.client.get(self.url) + self.assertContains(response,"Packets sent: 1") + + def test_message_to_be_confirmed_excluded(self): + msg = MessageModelFactory(status="pending_sender_confirmation") + response = self.client.get(self.url) + self.assertContains(response,"Packets sent: 0") + + class StartViewTest(TestCase): url = reverse('messaging:start') diff --git a/templates/base.html b/templates/base.html index 8752223..ad8a9a7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -26,6 +26,7 @@ {% url 'messaging:start' as url %} -

Packets sent: {{ packets_sent }}