From 2c4aaab4357de944904ccb5bca106180fd9f0905 Mon Sep 17 00:00:00 2001
From: echoduck <bekaluteshome@gmail.com>
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 @@
                 </form>
                 {% endif %}
             </ul>
+            <p>Packets sent: <b>{{ packets_sent }}</b></p>
         </div>
     </aside>
     <main>

From 1dcb6663285ad27ce191ce9b38ff34d9ae5be8a7 Mon Sep 17 00:00:00 2001
From: echoduck <bekaluteshome@gmail.com>
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: <b>1</b>")
+
+    def test_message_read_included(self):
+        msg = MessageModelFactory(status="read")
+        response = self.client.get(self.url)
+        self.assertContains(response,"Packets sent: <b>1</b>")
+
+    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: <b>0</b>")
+
+
 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 %}
             <a href="{{ url }}"><img src="{% static 'images/logo.png' %}" alt="Open-Source Happiness Packets" class="logo"/></a>
             <ul class="nav nav-stacked">
+                <li><a>Packets sent: <b>{{ packets_sent }}</b></a></li>
                 {% url 'messaging:send' as url %}
                 <li role="presentation" {% if url in request.path %}class="active"{% endif %}><a href="{{ url }}">Send some happiness!</a></li>
                 {% url 'messaging:start' as url %}
@@ -53,7 +54,6 @@
                 </form>
                 {% endif %}
             </ul>
-            <p>Packets sent: <b>{{ packets_sent }}</b></p>
         </div>
     </aside>
     <main>

