From b744eff7f692a58a1c209749e2fbff39ee0b443c Mon Sep 17 00:00:00 2001
From: Sander Roosendaal
Date: Mon, 19 Mar 2018 14:47:40 +0100
Subject: [PATCH] added breakthrough notification
---
rowers/tasks.py | 66 ++++++++++-------------
rowers/templates/breakthroughemail.html | 70 +++++++++++++++++++++++++
rowers/templates/csvemail.html | 2 +-
3 files changed, 98 insertions(+), 40 deletions(-)
create mode 100644 rowers/templates/breakthroughemail.html
diff --git a/rowers/tasks.py b/rowers/tasks.py
index 3f5be55a..2349eade 100644
--- a/rowers/tasks.py
+++ b/rowers/tasks.py
@@ -311,55 +311,43 @@ def handle_sendemail_breakthrough(workoutid, useremail,
btvalues=pd.DataFrame().to_json(),
**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 = "A breakthrough workout on rowsandall.com"
- message = "Dear " + userfirstname + ",\n"
- message += "Congratulations! Your recent workout has been analyzed"
- message += " by Rowsandall.com and it appears your fitness,"
- message += " as measured by Critical Power, has improved!"
- 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"
- message += "To add the workout to your Ranking workouts and see the updated CP plot, click the following link:\n"
- message += siteurl+"/rowers/workout/"
- message += str(workoutid)
- message += "/updatecp\n\n"
-
btvalues = pd.read_json(btvalues)
btvalues.sort_values('delta', axis=0, inplace=True)
- if not btvalues.empty:
- message += "These were the breakthrough values:\n"
- for t in btvalues.itertuples():
- delta = t.delta
- cpvalue = t.cpvalues
- pwr = t.pwr
+ tablevalues = [
+ {'delta': t.delta,
+ 'cpvalue': t.cpvalues,
+ 'pwr': t.pwr
+ } for t in btvalues.itertuples()
+ ]
- message += "Time: {delta} seconds\n".format(
- delta=delta
- )
- message += "New: {cpvalue:.0f} Watt\n".format(
- cpvalue=cpvalue
- )
- message += "Old: {pwr:.0f} Watt\n\n".format(
- pwr=pwr
- )
+ # send email with attachment
+ subject = "A breakthrough workout on rowsandall.com"
+ 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('breakthroughemail.html')
- message += "Best Regards, the Rowsandall Team"
+ d = {
+ 'first_name':userfirstname,
+ 'siteurl':siteurl,
+ 'workoutid':workoutid,
+ 'btvalues':tablevalues,
+ }
- email = EmailMessage(subject, message,
- 'Rowsandall ',
- [useremail])
+ 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")
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
@@ -367,7 +355,7 @@ def handle_sendemail_breakthrough(workoutid, useremail,
emailbounced = False
if not emailbounced:
- res = email.send()
+ res = msg.send()
diff --git a/rowers/templates/breakthroughemail.html b/rowers/templates/breakthroughemail.html
new file mode 100644
index 00000000..0c59145c
--- /dev/null
+++ b/rowers/templates/breakthroughemail.html
@@ -0,0 +1,70 @@
+
+
+{% load staticfiles %}
+{% load rowerfilters %}
+
+
+
+Dear {{ first_name }},
+
+
+ Congratulations! Your recent workout has been analyzed
+ by Rowsandall.com and it appears your fitness,
+ as measured by Critical Power, has improved!
+ 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 add the workout to your Ranking workouts and see the updated CP plot,
+ click the following link:
+
+
+
+
+ {{ siteurl }}/rowers/workout/{{ workoutid }}/updatecp
+
+
+{% if btvalues %}
+
+ These were the breakthrough values:
+
+
+
+
+
+ | Time (sec) | New Power (W) | Old Power |
+
+ {% for set in btvalues %}
+
+ | {{ set|lookup:"delta" }} |
+ {{ set|lookup:"cpvalue" }} |
+ {{ set|lookup:"pwr" }} |
+
+ {% endfor %}
+
+
+{% endif %}
+
+
+
+ To opt out of these email notifications, deselect the checkbox on your Profile
+ page under Account Information.
+
+
+
+ Best Regards, the Rowsandall Team
+
+
+
diff --git a/rowers/templates/csvemail.html b/rowers/templates/csvemail.html
index 95d44006..89b9b267 100644
--- a/rowers/templates/csvemail.html
+++ b/rowers/templates/csvemail.html
@@ -1,6 +1,6 @@
-
+
Dear {{ first_name }},