From e7e2ced5f516af7a68fe8fa4a124f64cb6ed8295 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 19 Mar 2018 15:49:57 +0100 Subject: [PATCH] a few new email templates --- rowers/tasks.py | 158 +++++++++++++----------- rowers/templates/breakthroughemail.html | 10 +- rowers/templates/csvemail.html | 11 +- rowers/templates/csvemail.txt | 5 - rowers/templates/emailbase.html | 16 +++ rowers/templates/gpxemail.html | 15 +++ rowers/templates/hardemail.html | 36 ++++++ rowers/templates/otwpoweremail.html | 35 ++++++ rowers/templates/summarymail.html | 15 +++ rowers/templates/tcxemail.html | 15 +++ rowers/templates/unrecognizedemail.html | 26 ++++ 11 files changed, 254 insertions(+), 88 deletions(-) delete mode 100644 rowers/templates/csvemail.txt create mode 100644 rowers/templates/emailbase.html create mode 100644 rowers/templates/gpxemail.html create mode 100644 rowers/templates/hardemail.html create mode 100644 rowers/templates/otwpoweremail.html create mode 100644 rowers/templates/summarymail.html create mode 100644 rowers/templates/tcxemail.html create mode 100644 rowers/templates/unrecognizedemail.html diff --git a/rowers/tasks.py b/rowers/tasks.py index 2349eade..6b0d06a9 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -371,31 +371,34 @@ def handle_sendemail_hard(workoutid, useremail, btvalues=pd.DataFrame().to_json(), debug=False,**kwargs): + if 'debug' in kwargs: + debug = kwargs['debug'] + else: + debug = False + siteurl = SITE_URL if debug: siteurl = SITE_URL_DEV # send email with attachment subject = "That was a pretty hard workout on rowsandall.com" - message = "Dear " + userfirstname + ",\n" - message += "Congratulations! Your recent workout has been analyzed" - message += " by Rowsandall.com and it appears that it was pretty hard work." - message += " You were working pretty close to your Critical Power\n\n" - message += " Critical Power (CP) is the power that you can " - message += "sustain for a given duration. For more, see this " - message += " article in the analytics blog:\n\n" - message += " http://analytics.rowsandall.com/2017/06/17/how-do-we-calculate-critical-power/ \n\n" - message += "Link to the workout: "+siteurl+"/rowers/workout/" - message += str(workoutid) - message += "/edit\n\n" + from_email = 'Rowsandall ' - message += "To opt out of these email notifications, deselect the checkbox on your Profile page under Account Information.\n\n" + htmly = get_template('hardemail.html') - message += "Best Regards, the Rowsandall Team" + d = { + 'first_name':userfirstname, + 'siteurl':siteurl, + 'workoutid':workoutid, + 'btvalues':tablevalues, + } + + html_content = htmly.render(d) + text_content = textify(html_content) + + msg = EmailMultiAlternatives(subject, text_content, from_email, [useremail]) + msg.attach_alternative(html_content, "text/html") - email = EmailMessage(subject, message, - 'Rowsandall ', - [useremail]) if 'emailbounced' in kwargs: emailbounced = kwargs['emailbounced'] @@ -403,7 +406,7 @@ def handle_sendemail_hard(workoutid, useremail, emailbounced = False if not emailbounced: - res = email.send() + res = msg.send() @@ -484,24 +487,19 @@ def handle_sendemail_unrecognizedowner(useremail, userfirstname, # send email with attachment fullemail = useremail subject = "Unrecognized file from Rowsandall.com" - message = "Dear " + userfirstname + ",\n\n" - message += """ - The file you tried to send to rowsandall.com was not recognized by - our email processing system. You may have sent a file in a format - that is not supported. Sometimes, rowing apps make file format changes. - When that happens, it takes some time for rowsandall.comm to make - the necessary changes on our side and support the app again. - The file has been sent to the developer at rowsandall.com for evaluation. + plaintext = get_template('csvemail.txt') + htmly = get_template('csvemail.html') + d = {'first_name':first_name} - """ + from_email = 'Rowsandall ' - message += "Best Regards, the Rowsandall Team" + html_content = htmly.render(d) + text_content = textify(html_content) - email = EmailMessage(subject, message, - 'Rowsandall ', - [fullemail]) + msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail]) + msg.attach_alternative(html_content, "text/html") if 'emailbounced' in kwargs: emailbounced = kwargs['emailbounced'] @@ -509,7 +507,7 @@ def handle_sendemail_unrecognizedowner(useremail, userfirstname, emailbounced = False if not emailbounced: - res = email.send() + res = msg.send() return 1 @@ -522,15 +520,20 @@ def handle_sendemailtcx(first_name, last_name, email, tcxfile,**kwargs): # send email with attachment fullemail = first_name + " " + last_name + " " + "<" + email + ">" subject = "File from Rowsandall.com" - message = "Dear " + first_name + ",\n\n" - message += "Please find attached the requested file for your workout.\n\n" - message += "Best Regards, the Rowsandall Team" - email = EmailMessage(subject, message, - 'Rowsandall ', - [fullemail]) + htmly = get_template('tcxemail.html') - email.attach_file(tcxfile) + d = {'first_name':first_name} + + from_email = 'Rowsandall ' + + 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") + + msg.attach_file(tcxfile) if 'emailbounced' in kwargs: emailbounced = kwargs['emailbounced'] @@ -538,7 +541,7 @@ def handle_sendemailtcx(first_name, last_name, email, tcxfile,**kwargs): emailbounced = False if not emailbounced: - res = email.send() + res = msg.send() # remove tcx file @@ -564,13 +567,8 @@ def handle_zip_file(emailfrom, subject, file,**kwargs): if debug: print "attaching" - if 'emailbounced' in kwargs: - emailbounced = kwargs['emailbounced'] - else: - emailbounced = False - if not emailbounced: - res = email.send() + res = email.send() if debug: @@ -582,25 +580,30 @@ def handle_zip_file(emailfrom, subject, file,**kwargs): @app.task def handle_sendemailsummary(first_name, last_name, email, csvfile, **kwargs): - # send email with attachment fullemail = first_name + " " + last_name + " " + "<" + email + ">" subject = "File from Rowsandall.com" - message = "Dear " + first_name + ",\n\n" - message += "Please find attached the requested summary file.\n\n" - message += "Best Regards, the Rowsandall Team" - email = EmailMessage(subject, message, - 'Rowsandall ', - [fullemail]) + htmly = get_template('summarymail.html') + + d = {'first_name':first_name} + + from_email = 'Rowsandall ' + + 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") + if os.path.isfile(csvfile): - email.attach_file(csvfile) + msg.attach_file(csvfile) else: csvfile2 = csvfile with gzip.open(csvfile + '.gz', 'rb') as f_in, open(csvfile2, 'wb') as f_out: shutil.copyfileobj(f_in, f_out) - email.attach_file(csvfile2) + msg.attach_file(csvfile2) os.remove(csvfile2) if 'emailbounced' in kwargs: @@ -609,7 +612,7 @@ def handle_sendemailsummary(first_name, last_name, email, csvfile, **kwargs): emailbounced = False if not emailbounced: - res = email.send() + res = msg.send() try: os.remove(csvfile) @@ -781,24 +784,35 @@ def handle_otwsetpower(self,f1, boattype, weightvalue, first_name, last_name, btvalues=btvalues.to_json()) - # send email - fullemail = first_name + " " + last_name + " " + "<" + email + ">" - subject = "Your Rowsandall OTW calculations are ready" - message = "Dear " + first_name + ",\n\n" - message += "Your Rowsandall OTW calculations are ready.\n" - message += "Thank you for using rowsandall.com.\n\n" - message += "Rowsandall OTW calculations have not been fully implemented yet.\n" - message += "We are now running an experimental version for debugging purposes. \n" - message += "Your wind/stream corrected plot is available here: " - message += siteurl+"/rowers/workout/" - message += str(workoutid) - message += "/interactiveotwplot\n\n" - message += "Please report any bugs/inconsistencies/unexpected results at rowsandall.slack.com or by reply to this email.\n\n" - message += "Best Regards, The Rowsandall Physics Department." - send_mail(subject, message, - 'Rowsandall Physics Department ', - [fullemail]) + subject = "Your OTW Physics Calculations are ready" + from_email = 'Rowsandall ' + fullemail = first_name + " " + last_name + " " + "<" + email + ">" + + htmly = get_template('otwpoweremail.html') + + d = { + 'first_name':first_name, + 'siteurl':siteurl, + 'workoutid':workoutid, + } + + 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") + + + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = msg.send() + + return 1 diff --git a/rowers/templates/breakthroughemail.html b/rowers/templates/breakthroughemail.html index 0c59145c..bd1107ab 100644 --- a/rowers/templates/breakthroughemail.html +++ b/rowers/templates/breakthroughemail.html @@ -1,10 +1,8 @@ - - +{% extends "emailbase.html" %} {% load staticfiles %} {% load rowerfilters %} - - +{% block body %}

Dear {{ first_name }},

@@ -66,5 +64,5 @@

Best Regards, the Rowsandall Team

- - +{% endblock %} + diff --git a/rowers/templates/csvemail.html b/rowers/templates/csvemail.html index 89b9b267..edb5ec7e 100644 --- a/rowers/templates/csvemail.html +++ b/rowers/templates/csvemail.html @@ -1,6 +1,8 @@ - - - +{% extends "emailbase.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block body %}

Dear {{ first_name }},

@@ -10,5 +12,4 @@

Best Regards, the Rowsandall Team

- - +{% endblock %} diff --git a/rowers/templates/csvemail.txt b/rowers/templates/csvemail.txt deleted file mode 100644 index 33071ef7..00000000 --- a/rowers/templates/csvemail.txt +++ /dev/null @@ -1,5 +0,0 @@ -Dear {{ first_name }}, - -Please find attached the requested file for your workout. - -Best Regards, the Rowsandall Team diff --git a/rowers/templates/emailbase.html b/rowers/templates/emailbase.html new file mode 100644 index 00000000..58c339eb --- /dev/null +++ b/rowers/templates/emailbase.html @@ -0,0 +1,16 @@ + + + +{% load staticfiles %} +{% load rowerfilters %} + + + + + {% block body %} + + {% endblock %} + + + + diff --git a/rowers/templates/gpxemail.html b/rowers/templates/gpxemail.html new file mode 100644 index 00000000..edb5ec7e --- /dev/null +++ b/rowers/templates/gpxemail.html @@ -0,0 +1,15 @@ +{% extends "emailbase.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block body %} +

Dear {{ first_name }},

+ +

+ Please find attached the requested file for your workout. +

+ +

+ Best Regards, the Rowsandall Team +

+{% endblock %} diff --git a/rowers/templates/hardemail.html b/rowers/templates/hardemail.html new file mode 100644 index 00000000..0ca5cf10 --- /dev/null +++ b/rowers/templates/hardemail.html @@ -0,0 +1,36 @@ +{% extends "emailbase.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block body %} +

Dear {{ first_name }},

+ +

+ Congratulations! Your recent workout has been analyzed + by Rowsandall.com and it appears it was pretty hard work. + You were working pretty close to your Critical Power. + Critical Power (CP) is the power that you can + sustain for a given duration. For more, see this + article in the analytics blog: +

+ +

+ + http://analytics.rowsandall.com/2017/06/17/how-do-we-calculate-critical-power/ +

+ +

+ Link to the workout: + {{ siteurl }}/rowers/workout/{{ workoutid }} +

+ + +

+ To opt out of these email notifications, deselect the checkbox on your Profile + page under Account Information. +

+ +

+ Best Regards, the Rowsandall Team +

+{% endblock %} diff --git a/rowers/templates/otwpoweremail.html b/rowers/templates/otwpoweremail.html new file mode 100644 index 00000000..8b90a830 --- /dev/null +++ b/rowers/templates/otwpoweremail.html @@ -0,0 +1,35 @@ +{% extends "emailbase.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block body %} +

Dear {{ first_name }},

+ +

+ Your Rowsandall OTW calculations are ready. +

+

+ Thank you for using rowsandall.com. +

+

+ Rowsandall OTW calculations have not been fully implemented yet. +

+

+ We are now running an experimental version for debugging purposes. +

+

+ Your wind/stream corrected plot is available here: + + {{ siteurl }}/rowers/workout/{{ workoutid }}/interactiveotwplot +

+

+ Please report any bugs/inconsistencies/unexpected results + by reply to this email. +

+ + + +

+ Best Regards, the Rowsandall Physics Department +

+{% endblock %} diff --git a/rowers/templates/summarymail.html b/rowers/templates/summarymail.html new file mode 100644 index 00000000..918f8443 --- /dev/null +++ b/rowers/templates/summarymail.html @@ -0,0 +1,15 @@ +{% extends "emailbase.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block body %} +

Dear {{ first_name }},

+ +

+ Please find attached the requested summary file. +

+ +

+ Best Regards, the Rowsandall Team +

+{% endblock %} diff --git a/rowers/templates/tcxemail.html b/rowers/templates/tcxemail.html new file mode 100644 index 00000000..edb5ec7e --- /dev/null +++ b/rowers/templates/tcxemail.html @@ -0,0 +1,15 @@ +{% extends "emailbase.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block body %} +

Dear {{ first_name }},

+ +

+ Please find attached the requested file for your workout. +

+ +

+ Best Regards, the Rowsandall Team +

+{% endblock %} diff --git a/rowers/templates/unrecognizedemail.html b/rowers/templates/unrecognizedemail.html new file mode 100644 index 00000000..bc6706ab --- /dev/null +++ b/rowers/templates/unrecognizedemail.html @@ -0,0 +1,26 @@ +{% extends "emailbase.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block body %} +

Dear {{ first_name }},

+ +

+ The file you tried to send to rowsandall.com was not recognized by + our email processing system. You may have sent a file in a format + that is not supported. Sometimes, rowing apps make file format changes. + When that happens, it takes some time for rowsandall.comm to make + the necessary changes on our side and support the app again. +

+ +

+ The file has been sent to the developer at rowsandall.com for evaluation. +

+ + + + +

+ Best Regards, the Rowsandall Team +

+{% endblock %}