From db7afcc1433d1863ea64ac0896302f01e2bf3584 Mon Sep 17 00:00:00 2001 From: Anna Philips 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_mime.add_header('Content-Disposition', 'attachment') + + message.attach(logo_mime) + message.send() From 02b1f5d1915cac0b1cc7db984ae1800f555a2063 Mon Sep 17 00:00:00 2001 From: Anna Philips 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 @@ - + - - - + + + 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 @@

We sent you a confirmation link to your email address. Follow the link to finalize sending your message.

- + - - - + + + {% block footer %}{% endblock %}