a few new email templates
This commit is contained in:
158
rowers/tasks.py
158
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 <info@rowsandall.com>'
|
||||
|
||||
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 <info@rowsandall.com>',
|
||||
[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 <info@rowsandall.com>'
|
||||
|
||||
message += "Best Regards, the Rowsandall Team"
|
||||
html_content = htmly.render(d)
|
||||
text_content = textify(html_content)
|
||||
|
||||
email = EmailMessage(subject, message,
|
||||
'Rowsandall <info@rowsandall.com>',
|
||||
[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 <info@rowsandall.com>',
|
||||
[fullemail])
|
||||
htmly = get_template('tcxemail.html')
|
||||
|
||||
email.attach_file(tcxfile)
|
||||
d = {'first_name':first_name}
|
||||
|
||||
from_email = 'Rowsandall <info@rowsandall.com>'
|
||||
|
||||
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 <info@rowsandall.com>',
|
||||
[fullemail])
|
||||
htmly = get_template('summarymail.html')
|
||||
|
||||
d = {'first_name':first_name}
|
||||
|
||||
from_email = 'Rowsandall <info@rowsandall.com>'
|
||||
|
||||
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 <info@rowsandall.com>',
|
||||
[fullemail])
|
||||
subject = "Your OTW Physics Calculations are ready"
|
||||
from_email = 'Rowsandall <info@rowsandall.com>'
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user