From 77bb53466ed76347ecd337b4a0ac7239dc7f02e9 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 18 Mar 2018 09:55:49 +0100 Subject: [PATCH 1/3] added emailbounced keyword to tasks --- rowers/dataprep.py | 56 +++------ rowers/models.py | 7 +- rowers/tasks.py | 186 ++++++++++++++++++++++++---- rowers/templates/privacypolicy.html | 3 +- rowers/views.py | 56 ++++++++- 5 files changed, 242 insertions(+), 66 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 24746f04..cd983a7b 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -1048,7 +1048,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower', powermean = df['power'].mean() except KeyError: powermean = 0 - + if powermean != 0: thesecs = totaltime maxt = 1.05 * thesecs @@ -1071,45 +1071,27 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower', # submit email task to send email about breakthrough workout if isbreakthrough: a_messages.info( - r.user, 'It looks like you have a new breakthrough workout') - if settings.DEBUG and r.getemailnotifications: - res = handle_sendemail_breakthrough.delay(w.id, r.user.email, - r.user.first_name, - r.user.last_name, - btvalues=btvalues.to_json()) - elif r.getemailnotifications: - try: - res = queuehigh.enqueue( - handle_sendemail_breakthrough(w.id, - r.user.email, - r.user.first_name, - r.user.last_name, - btvalues=btvalues.to_json())) - except AttributeError: - pass - else: - pass + r.user, 'It looks like you have a new breakthrough workout' + ) + if r.getemailnotifications and not r.emailbounced: + job = myqueue(queuehigh,handle_sendemail_breakthrough, + w.id, + r.user.email, + r.user.first_name, + r.user.last_name, + btvalues=btvalues.to_json()) + # submit email task to send email about breakthrough workout if ishard: a_messages.info(r.user, 'That was a pretty hard workout') - if settings.DEBUG and r.getemailnotifications: - res = handle_sendemail_hard.delay(w.id, r.user.email, - r.user.first_name, - r.user.last_name, - btvalues=btvalues.to_json()) - elif r.getemailnotifications: - try: - res = queuehigh.enqueue( - handle_sendemail_hard(w.id, - r.user.email, - r.user.first_name, - r.user.last_name, - btvalues=btvalues.to_json())) - except AttributeError: - pass - else: - pass - + if r.getemailnotifications and not r.emailbounced: + job = myqueue(queuehigh,handle_sendemail_hard, + w.id, + r.user.email, + r.user.first_name, + r.user.last_name, + btvalues=btvalues.to_json()) + return (w.id, message) diff --git a/rowers/models.py b/rowers/models.py index c5afa452..5ec4a937 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -574,6 +574,9 @@ class Rower(models.Model): emailbounced = models.BooleanField(default=False, verbose_name='Email Address Bounced') + getimportantemails = models.BooleanField(default=True, + verbose_name='Get Important Emails') + rowerplan = models.CharField(default='basic',max_length=30, choices=plans) @@ -1586,7 +1589,9 @@ class RowerPowerZonesForm(ModelForm): class AccountRowerForm(ModelForm): class Meta: model = Rower - fields = ['sex','birthdate','weightcategory','getemailnotifications', + fields = ['sex','birthdate','weightcategory', + 'getemailnotifications', + 'getimportantemails', 'defaulttimezone','showfavoritechartnotes', 'defaultlandingpage'] diff --git a/rowers/tasks.py b/rowers/tasks.py index ebac2355..42568a6e 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -253,7 +253,7 @@ def handle_new_workout_from_file(r, f2, @app.task -def handle_updatedps(useremail, workoutids, debug=False): +def handle_updatedps(useremail, workoutids, debug=False,**kwargs): for wid, f1 in workoutids: havedata = 1 try: @@ -270,6 +270,7 @@ def handle_updatedps(useremail, workoutids, debug=False): if havedata: update_strokedata(wid, rowdata.df, debug=debug) + subject = "Rowsandall.com Your Distance per Stroke metric has been updated" message = "All your workouts now have Distance per Stroke" @@ -277,7 +278,13 @@ def handle_updatedps(useremail, workoutids, debug=False): 'Rowsandall ', [useremail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() return 1 @@ -340,7 +347,15 @@ def handle_sendemail_breakthrough(workoutid, useremail, 'Rowsandall ', [useremail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + + # remove tcx file return 1 @@ -380,7 +395,15 @@ def handle_sendemail_hard(workoutid, useremail, 'Rowsandall ', [useremail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + + # remove tcx file return 1 @@ -400,7 +423,14 @@ def handle_sendemail_userdeleted(name, email, debug=False, **kwargs): 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -426,7 +456,14 @@ def handle_sendemail_unrecognized(unrecognizedfile, useremail, except IOError: pass - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + # remove tcx file try: @@ -464,7 +501,14 @@ def handle_sendemail_unrecognizedowner(useremail, userfirstname, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -486,7 +530,14 @@ def handle_sendemailtcx(first_name, last_name, email, tcxfile,**kwargs): email.attach_file(tcxfile) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + # remove tcx file os.remove(tcxfile) @@ -510,7 +561,16 @@ def handle_zip_file(emailfrom, subject, file,**kwargs): email.attach_file(file) if debug: print "attaching" - res = email.send() + + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + + if debug: print "sent" time.sleep(60) @@ -541,7 +601,14 @@ def handle_sendemailsummary(first_name, last_name, email, csvfile, **kwargs): email.attach_file(csvfile2) os.remove(csvfile2) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + try: os.remove(csvfile) except: @@ -579,7 +646,14 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs): os.remove(csvfile2) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -970,7 +1044,14 @@ def handle_sendemail_invite(email, name, code, teamname, manager, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -1004,7 +1085,14 @@ def handle_sendemailnewresponse(first_name, last_name, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -1034,7 +1122,14 @@ def handle_sendemailnewcomment(first_name, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -1059,7 +1154,14 @@ def handle_sendemail_request(email, name, code, teamname, requestor, id, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -1080,7 +1182,14 @@ def handle_sendemail_request_accept(email, name, teamname, managername, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -1102,7 +1211,14 @@ def handle_sendemail_request_reject(email, name, teamname, managername, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -1124,7 +1240,14 @@ def handle_sendemail_member_dropped(email, name, teamname, managername, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -1147,7 +1270,14 @@ def handle_sendemail_team_removed(email, name, teamname, managername, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -1169,7 +1299,14 @@ def handle_sendemail_invite_reject(email, name, teamname, managername, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 @@ -1187,7 +1324,14 @@ def handle_sendemail_invite_accept(email, name, teamname, managername, 'Rowsandall ', [fullemail]) - res = email.send() + if 'emailbounced' in kwargs: + emailbounced = kwargs['emailbounced'] + else: + emailbounced = False + + if not emailbounced: + res = email.send() + return 1 diff --git a/rowers/templates/privacypolicy.html b/rowers/templates/privacypolicy.html index a3faa516..34f72020 100644 --- a/rowers/templates/privacypolicy.html +++ b/rowers/templates/privacypolicy.html @@ -105,7 +105,8 @@ are limited to substantial changes in terms and conditions and other announcements impacting the terms on which you use the site. We will it is important to get these messages to you. If you do not with - to receive such emails, you can indicate so in the user settings. + to receive such emails, you can indicate so in the user settings ("Get + Important Emails" under "Account Information").

diff --git a/rowers/views.py b/rowers/views.py index 69efcd63..67938eb2 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -1708,7 +1708,18 @@ def workout_tcxemail_view(request,id=0): r = getrower(request.user) w = get_workout(id) if (checkworkoutuser(request.user,w)): - tcxfile,tcxmessg = stravastuff.createstravaworkoutdata(w,dozip=False) + if r.emailbounced: + message = "Please check your email address first. Email to this address bounced." + messages.error(request, message) + return HttpResponseRedirect( + reverse(workout_export_view, + kwargs = { + 'id':str(w.id), + }) + ) + + + tcxfile,tcxmessg = stravastuff.createstravaworkoutdata(w,dozip=False) if tcxfile == 0: message = "Something went wrong (TCX export) "+tcxmessg messages.error(request,message) @@ -1726,11 +1737,12 @@ def workout_tcxemail_view(request,id=0): successmessage = "The TCX file was sent to you per email" messages.info(request,successmessage) - url = reverse(workout_export_view, - kwargs = { - 'id':str(w.id), - }) + + url = reverse(workout_export_view, + kwargs = { + 'id':str(w.id), + }) response = HttpResponseRedirect(url) else: @@ -1750,6 +1762,16 @@ def workout_gpxemail_view(request,id=0): message = "" successmessage = "" r = Rower.objects.get(user=request.user) + if r.emailbounced: + message = "Please check your email address first. Email to this address bounced." + messages.error(request, message) + return HttpResponseRedirect( + reverse(workout_export_view, + kwargs = { + 'id':str(w.id), + }) + ) + w = get_workout(id) if (checkworkoutuser(request.user,w)): @@ -1787,6 +1809,15 @@ def workout_gpxemail_view(request,id=0): @login_required() def workouts_summaries_email_view(request): r = getrower(request.user) + if r.emailbounced: + message = "Please check your email address first. Email to this address bounced." + messages.error(request, message) + return HttpResponseRedirect( + reverse(workout_export_view, + kwargs = { + 'id':str(w.id), + }) + ) if request.method == 'POST': form = DateRangeForm(request.POST) @@ -1819,6 +1850,16 @@ def workouts_summaries_email_view(request): def workout_csvemail_view(request,id=0): message = "" r = getrower(request.user) + if r.emailbounced: + message = "Please check your email address first. Email to this address bounced." + messages.error(request, message) + return HttpResponseRedirect( + reverse(workout_export_view, + kwargs = { + 'id':str(w.id), + }) + ) + w = get_workout(id) if (checkworkoutuser(request.user,w)): @@ -11229,6 +11270,7 @@ def rower_edit_view(request,rowerid=0,message=""): birthdate = cd['birthdate'] showfavoritechartnotes = cd['showfavoritechartnotes'] getemailnotifications = cd['getemailnotifications'] + getimportantemails = cd['getimportantemails'] defaulttimezone=cd['defaulttimezone'] u = r.user if u.email != email and len(email): @@ -11247,6 +11289,7 @@ def rower_edit_view(request,rowerid=0,message=""): r.defaulttimezone=defaulttimezone r.weightcategory = weightcategory r.getemailnotifications = getemailnotifications + r.getimportantemails = getimportantemails r.defaultlandingpage = defaultlandingpage r.showfavoritechartnotes = showfavoritechartnotes r.sex = sex @@ -11587,7 +11630,8 @@ def rower_calcdps_view(request): r = getrower(request.user) ws = [(w.id,w.csvfilename) for w in Workout.objects.filter(user=r)] - res = myqueue(queue,handle_updatedps,r.user.email,ws,debug=False) + res = myqueue(queue,handle_updatedps,r.user.email,ws,debug=False, + emailbounced=r.emailbounced) messages.info(request,"Your workouts are being updated in the background. You will receive email when this is done.") From f5f6de50c6b29aacd1129af4dd5cd9d5048a0e6f Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 18 Mar 2018 10:17:01 +0100 Subject: [PATCH 2/3] logic around emailbounces --- rowers/views.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/rowers/views.py b/rowers/views.py index 67938eb2..d5d58091 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -1733,7 +1733,9 @@ def workout_tcxemail_view(request,id=0): r.user.first_name, r.user.last_name, r.user.email, - tcxfile) + tcxfile, + emailbounced = r.emailbounced + ) successmessage = "The TCX file was sent to you per email" messages.info(request,successmessage) @@ -1782,7 +1784,9 @@ def workout_gpxemail_view(request,id=0): res = myqueue(queuehigh,handle_sendemailtcx, r.user.first_name, r.user.last_name, - r.user.email,gpxfilename) + r.user.email,gpxfilename, + emailbounced = r.emailbounced + ) successmessage = "The GPX file was sent to you per email" @@ -1834,7 +1838,9 @@ def workouts_summaries_email_view(request): r.user.first_name, r.user.last_name, r.user.email, - filename) + filename, + emailbounced = r.emailbounced + ) messages.info(request,'The summary CSV file was sent to you per email') else: form = DateRangeForm() @@ -1866,7 +1872,9 @@ def workout_csvemail_view(request,id=0): csvfile = w.csvfilename res = myqueue(queuehigh,handle_sendemailcsv,r.user.first_name, r.user.last_name, - r.user.email,csvfile) + r.user.email,csvfile, + emailbounced = r.emailbounced + ) successmessage = "The CSV file was sent to you per email" messages.info(request,successmessage) @@ -7176,6 +7184,7 @@ def workout_otwsetpower_view(request,id=0,message="",successmessage=""): ps=[r.p0,r.p1,r.p2,r.p3], ratio=r.cpratio, quick_calc = quick_calc, + emailbounced = r.emailbounced ) try: @@ -8578,12 +8587,15 @@ def workout_comment_view(request,id=0): r.user.email, request.user.first_name, request.user.last_name, - comment,w.name,w.id) + comment,w.name,w.id, + emailbounced = r.emailbounced + ) commenters = {oc.user for oc in comments if oc.notification} for u in commenters: a_messages.info(u,message) if u != request.user and u != r.user: + ocr = Rower.objects.get(user=u) res = myqueue(queuelow, handle_sendemailnewresponse, u.first_name, @@ -8594,7 +8606,9 @@ def workout_comment_view(request,id=0): comment, w.name, w.id, - c.id) + c.id, + emailbounced = ocr.emailbounced + ) url = reverse(workout_comment_view,kwargs = { 'id':id}) @@ -10377,7 +10391,9 @@ def team_workout_upload_view(request,message="", handle_zip_file, r.user.email, t, - f2) + f2, + emailbounced = r.emailbounced + ) messages.info( request, From f249565ab3ce6bdc85b18d465eb2e5ac8b62242d Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 18 Mar 2018 10:24:24 +0100 Subject: [PATCH 3/3] added raise500 for superuser to check --- rowers/urls.py | 1 + rowers/views.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/rowers/urls.py b/rowers/urls.py index 7922359b..2b513bb5 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -356,6 +356,7 @@ urlpatterns = [ url(r'^me/invitation/(?P\d+)/reject$',views.invitation_reject_view), url(r'^me/invitation/(?P\d+)/revoke$',views.invitation_revoke_view), url(r'^me/invitation/$',views.rower_invitations_view), + url(r'^me/raise500/$',views.raise_500), url(r'^me/invitation/(\w+.*)/$',views.rower_invitations_view), url(r'^me/request/(?P\d+)/revoke',views.request_revoke_view), url(r'^me/request/(?P\d+)/reject',views.request_reject_view), diff --git a/rowers/views.py b/rowers/views.py index d5d58091..fb69cd79 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -398,6 +398,13 @@ def kill_async_job(request,id='aap'): return HttpResponseRedirect(url) +@login_required() +def raise_500(request): + if request.user.is_superuser: + raise ValueError + else: + return HttpResponse("invalid") + @login_required() def test_job_view(request,aantal=100):