From 5afb2477cf16b6a442ed15cc6d62033a0b649850 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 19 Mar 2018 12:44:41 +0100 Subject: [PATCH] cleaning up email templates --- rowers/tasks.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/rowers/tasks.py b/rowers/tasks.py index 98e3c3d5..3f5be55a 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -5,7 +5,7 @@ import gc import gzip import shutil import numpy as np - +import re from scipy import optimize @@ -30,6 +30,13 @@ import pandas as pd from django_rq import job from django.utils import timezone +from django.utils.html import strip_tags + +def textify(html): + # Remove html tags and continuous whitespaces + text_only = re.sub('[ \t]+', ' ', strip_tags(html)) + # Strip single spaces in the beginning of each line + return text_only.replace('\n ', '\n').strip() from utils import deserialize_list @@ -640,9 +647,9 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs): from_email = 'Rowsandall ' - text_content = plaintext.render(d) html_content = htmly.render(d) - + text_content = textify(html_content) + msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail]) msg.attach_alternative(html_content, "text/html")