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")