From db7afcc1433d1863ea64ac0896302f01e2bf3584 Mon Sep 17 00:00:00 2001
From: Anna Philips <ms.annaphilips@gmail.com>
Date: Aug 04 2018 05:35:42 +0000
Subject: [PATCH 1/2] Adds celery and redis


---

diff --git a/happinesspackets/_celery.py b/happinesspackets/_celery.py
new file mode 100644
index 0000000..d61111f
--- /dev/null
+++ b/happinesspackets/_celery.py
@@ -0,0 +1,10 @@
+import os
+from celery import Celery
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'happinesspackets.settings')
+
+app = Celery('happinesspackets')
+app.config_from_object('django.conf:settings')
+
+# Load task modules from all registered Django app configs.
+app.autodiscover_tasks()
diff --git a/happinesspackets/messaging/models.py b/happinesspackets/messaging/models.py
index 63b462d..c11d1a0 100644
--- a/happinesspackets/messaging/models.py
+++ b/happinesspackets/messaging/models.py
@@ -11,7 +11,8 @@ from django.utils.crypto import salted_hmac
 from model_utils import Choices
 from model_utils.models import TimeStampedModel
 
-from happinesspackets.utils.misc import readable_random_token, send_html_mail
+from happinesspackets.utils.misc import readable_random_token
+from happinesspackets.tasks import send_html_mail
 
 logger = logging.getLogger(__name__)
 BLACKLIST_HMAC_SALT = 'happinesspackets.messaging.views.BlacklistEmailView'
@@ -79,7 +80,7 @@ class Message(TimeStampedModel):
         subject = ' '.join(subject.splitlines())
         body_txt = render_to_string('messaging/sender_confirmation_mail.txt', context)
         body_html = render_to_string('messaging/sender_confirmation_mail.html', context)
-        send_html_mail(subject, body_txt, body_html, self.sender_email)
+        send_html_mail.delay(subject, body_txt, body_html, self.sender_email)
         self.save()
 
     def send_to_recipient(self, use_https, domain):
@@ -102,7 +103,7 @@ class Message(TimeStampedModel):
         subject = ' '.join(subject.splitlines())
         body_txt = render_to_string('messaging/recipient_mail.txt', context)
         body_html = render_to_string('messaging/recipient_mail.html', context)
-        send_html_mail(subject, body_txt, body_html, self.recipient_email)
+        send_html_mail.delay(subject, body_txt, body_html, self.recipient_email)
         self.save()
 
 
diff --git a/happinesspackets/settings/base.py b/happinesspackets/settings/base.py
index ece8402..db439e9 100644
--- a/happinesspackets/settings/base.py
+++ b/happinesspackets/settings/base.py
@@ -186,6 +186,11 @@ LOGGING = {
     }
 }
 
+REDIS_HOST = 'localhost'
+REDIS_PORT = '6379'
+BROKER_URL = 'redis://' + REDIS_HOST + ':' + REDIS_PORT + '/0'
+BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600}
+CELERY_RESULT_BACKEND = 'redis://' + REDIS_HOST + ':' + REDIS_PORT + '/0'
 
 def get_env_variable(var_name):
     """ Get the environment variable or return exception """
diff --git a/happinesspackets/tasks.py b/happinesspackets/tasks.py
new file mode 100644
index 0000000..989bab0
--- /dev/null
+++ b/happinesspackets/tasks.py
@@ -0,0 +1,22 @@
+import logging
+
+from happinesspackets._celery import app
+from email.mime.image import MIMEImage
+from django.conf import settings
+from django.core.mail import EmailMultiAlternatives
+
+
+@app.task
+def send_html_mail(subject, body_txt, body_html, recipient):
+    message = EmailMultiAlternatives(subject, body_txt, settings.DEFAULT_FROM_EMAIL, [recipient])
+    message.attach_alternative(body_html, 'text/html')
+    message.mixed_subtype = 'related'
+
+    logo_file = open(settings.STATIC_ROOT.child('images').child('logo.png'))
+    logo_mime = MIMEImage(logo_file.read())
+    logo_file.close()
+    logo_mime.add_header('Content-ID', '<logo.png@happinesspackets.io>')
+    logo_mime.add_header('Content-Disposition', 'attachment')
+
+    message.attach(logo_mime)
+    message.send()

From 02b1f5d1915cac0b1cc7db984ae1800f555a2063 Mon Sep 17 00:00:00 2001
From: Anna Philips <ms.annaphilips@gmail.com>
Date: Aug 05 2018 04:17:52 +0000
Subject: [PATCH 2/2] Update hashtags


---

diff --git a/templates/follow.html b/templates/follow.html
index 84faa2f..4c9b017 100644
--- a/templates/follow.html
+++ b/templates/follow.html
@@ -1,6 +1,6 @@
-<a class="g-interactivepost sharebutton google" data-contenturl="https://happinesspackets.fedorainfracloud.org/" data-clientid="427442962349-biuc5ks65luss5h3v5oqtj15jigaqoib.apps.googleusercontent.com" data-cookiepolicy="single_host_origin" data-prefilltext="#FedoraAppreciationWeek2k18" data-calltoactionurl="http://plus.google.com/pages/create"><i class="fab fa-google-plus-g fa-lg"></i> Share #FedoraAppreciationWeek2k18</a>
+<a class="g-interactivepost sharebutton google" data-contenturl="https://happinesspackets.fedorainfracloud.org/" data-clientid="427442962349-biuc5ks65luss5h3v5oqtj15jigaqoib.apps.googleusercontent.com" data-cookiepolicy="single_host_origin" data-prefilltext="#WeAreFedora" data-calltoactionurl="http://plus.google.com/pages/create"><i class="fab fa-google-plus-g fa-lg"></i> Share #WeAreFedora</a>
 <script type="text/javascript">(function() {var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/client:plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);})();</script>
-<a id="fb" class="sharebutton"><i class="fab fa-facebook fa-lg"></i> Share #FedoraAppreciationWeek2k18</a>
-<script>document.getElementById('fb').onclick = function() {FB.ui({method: 'share', mobile_iframe: true, hashtag: '#FedoraAppreciationWeek2k18', href: 'https://happinesspackets.fedorainfracloud.org/',}, function(response){});}</script>
-<a href="https://twitter.com/intent/tweet?button_hashtag=FedoraAppreciationWeek2k18" class="twitter-hashtag-button" data-size="large" data-dnt="true">Tweet #FedoraAppreciationWeek2k18</a>
+<a id="fb" class="sharebutton"><i class="fab fa-facebook fa-lg"></i> Share #WeAreFedora</a>
+<script>document.getElementById('fb').onclick = function() {FB.ui({method: 'share', mobile_iframe: true, hashtag: '#WeAreFedora', href: 'https://happinesspackets.fedorainfracloud.org/',}, function(response){});}</script>
+<a href="https://twitter.com/intent/tweet?button_hashtag=WeAreFedora" class="twitter-hashtag-button" data-size="large" data-dnt="true">Tweet #WeAreFedora</a>
 <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
diff --git a/templates/messaging/message_sender_confirmation_sent.html b/templates/messaging/message_sender_confirmation_sent.html
index 4781904..fe259b5 100644
--- a/templates/messaging/message_sender_confirmation_sent.html
+++ b/templates/messaging/message_sender_confirmation_sent.html
@@ -9,11 +9,11 @@
     <p>
         We sent you a confirmation link to your email address. Follow the link to finalize sending your message.
     </p>
-    <a class="g-interactivepost sharebutton google" data-contenturl="https://happinesspackets.fedorainfracloud.org/" data-clientid="427442962349-biuc5ks65luss5h3v5oqtj15jigaqoib.apps.googleusercontent.com" data-cookiepolicy="single_host_origin" data-prefilltext="I just sent a happiness packet to thank a @fedora community member #FedoraAppreciationWeek2k18" data-calltoactionurl="http://plus.google.com/pages/create"><i class="fab fa-google-plus-g fa-lg"></i> Share #FedoraAppreciationWeek2k18</a>
+    <a class="g-interactivepost sharebutton google" data-contenturl="https://happinesspackets.fedorainfracloud.org/" data-clientid="427442962349-biuc5ks65luss5h3v5oqtj15jigaqoib.apps.googleusercontent.com" data-cookiepolicy="single_host_origin" data-prefilltext="I just sent a happiness packet to thank a @fedora community member #WeAreFedora" data-calltoactionurl="http://plus.google.com/pages/create"><i class="fab fa-google-plus-g fa-lg"></i> Share #WeAreFedora</a>
     <script type="text/javascript">(function() {var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/client:plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);})();</script>
-    <a id="fb" class="sharebutton"><i class="fab fa-facebook fa-lg"></i> Share #FedoraAppreciationWeek2k18</a>
-    <script>document.getElementById('fb').onclick = function() {FB.ui({method: 'share', mobile_iframe: true, hashtag: '#FedoraAppreciationWeek2k18', href: 'https://happinesspackets.fedorainfracloud.org/',}, function(response){});}</script>
-    <a href="https://twitter.com/intent/tweet?button_hashtag=FedoraAppreciationWeek2k18&text=I%20just%20sent%20a%20happiness%20packet%20to%20thank%20a%20@fedora%20community%20member" class="twitter-hashtag-button" data-size="large" data-dnt="true">Tweet #FedoraAppreciationWeek2k18</a>
+    <a id="fb" class="sharebutton"><i class="fab fa-facebook fa-lg"></i> Share #WeAreFedora</a>
+    <script>document.getElementById('fb').onclick = function() {FB.ui({method: 'share', mobile_iframe: true, hashtag: '#WeAreFedora', href: 'https://happinesspackets.fedorainfracloud.org/',}, function(response){});}</script>
+    <a href="https://twitter.com/intent/tweet?button_hashtag=WeAreFedora&text=I%20just%20sent%20a%20happiness%20packet%20to%20thank%20a%20@fedora%20community%20member" class="twitter-hashtag-button" data-size="large" data-dnt="true">Tweet #WeAreFedora</a>
     <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
     {% block footer %}{% endblock %}
 

