From b0d6430e5beaae0442951dbf8410e79beb435211 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 16 Jun 2017 08:46:13 +0200 Subject: [PATCH] new user sample data --- rowers/dataprep.py | 11 ++++++++++- rowers/tasks.py | 36 ++++++++++++++++++++++++++++++++++++ rowers/views.py | 4 ++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index ae86fca3..634cb0b7 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -688,7 +688,16 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower', # submit email task to send email about breakthrough workout if isbreakthrough: - pass + if settings.DEBUG: + res = handle_sendemail_breakthrough(w.id,r.user.email, + r.user.first_name, + r.user.last_name) + else: + res = queuehigh.enqueue( + handle_sendemail_breakthrough(w.id, + r.user.email, + r.user.first_name, + r.user.last_name)) if privacy == 'visible': ts = Team.objects.filter(rower=r) diff --git a/rowers/tasks.py b/rowers/tasks.py index 34e33726..56e20c35 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -47,6 +47,42 @@ def handle_new_workout_from_file(r,f2, return new_workout_from_file(r,f2,workouttype, title,makeprivate,notes) +# send email when a breakthrough workout is uploaded +@app.task +def handle_sendemail_breakthrough(workoutid,useremail,userfirstname,userlastname): + + # 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 += " [link to article to be written]\n\n" + message += "Link to the workout http://rowsandall.com/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 += "http://rowsandall.com/rowers/workout/" + message += str(workoutid) + message += "/updatecp\n\n" + + message += "Best Regards, the Rowsandall Team" + + email = EmailMessage(subject, message, + 'Rowsandall ', + [useremail]) + + + res = email.send() + + # remove tcx file + os.remove(unrecognizedfile) + return 1 + + # send email to me when an unrecognized file is uploaded @app.task def handle_sendemail_unrecognized(unrecognizedfile,useremail): diff --git a/rowers/views.py b/rowers/views.py index 325a43b1..26e67f55 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -343,6 +343,10 @@ def rower_register_view(request): response = dataprep.new_workout_from_file(therower,f2, title='New User Sample Data', notes='This is an example workout to get you started') + newworkoutid = response[0] + w = Workout.objects.get(id=newworkoutid) + w.startdatetime = timezone.now() + w.save() # Create and send email fullemail = first_name + " " + last_name + " " + "<" + email + ">"