Private
Public Access
1
0

added emailbounced keyword to tasks

This commit is contained in:
Sander Roosendaal
2018-03-18 09:55:49 +01:00
parent 4f1433830e
commit 77bb53466e
5 changed files with 242 additions and 66 deletions

View File

@@ -1048,7 +1048,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
powermean = df['power'].mean() powermean = df['power'].mean()
except KeyError: except KeyError:
powermean = 0 powermean = 0
if powermean != 0: if powermean != 0:
thesecs = totaltime thesecs = totaltime
maxt = 1.05 * thesecs 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 # submit email task to send email about breakthrough workout
if isbreakthrough: if isbreakthrough:
a_messages.info( a_messages.info(
r.user, 'It looks like you have a new breakthrough workout') 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, if r.getemailnotifications and not r.emailbounced:
r.user.first_name, job = myqueue(queuehigh,handle_sendemail_breakthrough,
r.user.last_name, w.id,
btvalues=btvalues.to_json()) r.user.email,
elif r.getemailnotifications: r.user.first_name,
try: r.user.last_name,
res = queuehigh.enqueue( btvalues=btvalues.to_json())
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
# submit email task to send email about breakthrough workout # submit email task to send email about breakthrough workout
if ishard: if ishard:
a_messages.info(r.user, 'That was a pretty hard workout') a_messages.info(r.user, 'That was a pretty hard workout')
if settings.DEBUG and r.getemailnotifications: if r.getemailnotifications and not r.emailbounced:
res = handle_sendemail_hard.delay(w.id, r.user.email, job = myqueue(queuehigh,handle_sendemail_hard,
r.user.first_name, w.id,
r.user.last_name, r.user.email,
btvalues=btvalues.to_json()) r.user.first_name,
elif r.getemailnotifications: r.user.last_name,
try: btvalues=btvalues.to_json())
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
return (w.id, message) return (w.id, message)

View File

@@ -574,6 +574,9 @@ class Rower(models.Model):
emailbounced = models.BooleanField(default=False, emailbounced = models.BooleanField(default=False,
verbose_name='Email Address Bounced') verbose_name='Email Address Bounced')
getimportantemails = models.BooleanField(default=True,
verbose_name='Get Important Emails')
rowerplan = models.CharField(default='basic',max_length=30, rowerplan = models.CharField(default='basic',max_length=30,
choices=plans) choices=plans)
@@ -1586,7 +1589,9 @@ class RowerPowerZonesForm(ModelForm):
class AccountRowerForm(ModelForm): class AccountRowerForm(ModelForm):
class Meta: class Meta:
model = Rower model = Rower
fields = ['sex','birthdate','weightcategory','getemailnotifications', fields = ['sex','birthdate','weightcategory',
'getemailnotifications',
'getimportantemails',
'defaulttimezone','showfavoritechartnotes', 'defaulttimezone','showfavoritechartnotes',
'defaultlandingpage'] 'defaultlandingpage']

View File

@@ -253,7 +253,7 @@ def handle_new_workout_from_file(r, f2,
@app.task @app.task
def handle_updatedps(useremail, workoutids, debug=False): def handle_updatedps(useremail, workoutids, debug=False,**kwargs):
for wid, f1 in workoutids: for wid, f1 in workoutids:
havedata = 1 havedata = 1
try: try:
@@ -270,6 +270,7 @@ def handle_updatedps(useremail, workoutids, debug=False):
if havedata: if havedata:
update_strokedata(wid, rowdata.df, debug=debug) update_strokedata(wid, rowdata.df, debug=debug)
subject = "Rowsandall.com Your Distance per Stroke metric has been updated" subject = "Rowsandall.com Your Distance per Stroke metric has been updated"
message = "All your workouts now have Distance per Stroke" message = "All your workouts now have Distance per Stroke"
@@ -277,7 +278,13 @@ def handle_updatedps(useremail, workoutids, debug=False):
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[useremail]) [useremail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -340,7 +347,15 @@ def handle_sendemail_breakthrough(workoutid, useremail,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[useremail]) [useremail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
# remove tcx file # remove tcx file
return 1 return 1
@@ -380,7 +395,15 @@ def handle_sendemail_hard(workoutid, useremail,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[useremail]) [useremail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
# remove tcx file # remove tcx file
return 1 return 1
@@ -400,7 +423,14 @@ def handle_sendemail_userdeleted(name, email, debug=False, **kwargs):
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -426,7 +456,14 @@ def handle_sendemail_unrecognized(unrecognizedfile, useremail,
except IOError: except IOError:
pass pass
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
# remove tcx file # remove tcx file
try: try:
@@ -464,7 +501,14 @@ def handle_sendemail_unrecognizedowner(useremail, userfirstname,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -486,7 +530,14 @@ def handle_sendemailtcx(first_name, last_name, email, tcxfile,**kwargs):
email.attach_file(tcxfile) 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 # remove tcx file
os.remove(tcxfile) os.remove(tcxfile)
@@ -510,7 +561,16 @@ def handle_zip_file(emailfrom, subject, file,**kwargs):
email.attach_file(file) email.attach_file(file)
if debug: if debug:
print "attaching" print "attaching"
res = email.send()
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
if debug: if debug:
print "sent" print "sent"
time.sleep(60) time.sleep(60)
@@ -541,7 +601,14 @@ def handle_sendemailsummary(first_name, last_name, email, csvfile, **kwargs):
email.attach_file(csvfile2) email.attach_file(csvfile2)
os.remove(csvfile2) os.remove(csvfile2)
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
try: try:
os.remove(csvfile) os.remove(csvfile)
except: except:
@@ -579,7 +646,14 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs):
os.remove(csvfile2) os.remove(csvfile2)
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -970,7 +1044,14 @@ def handle_sendemail_invite(email, name, code, teamname, manager,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -1004,7 +1085,14 @@ def handle_sendemailnewresponse(first_name, last_name,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -1034,7 +1122,14 @@ def handle_sendemailnewcomment(first_name,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -1059,7 +1154,14 @@ def handle_sendemail_request(email, name, code, teamname, requestor, id,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -1080,7 +1182,14 @@ def handle_sendemail_request_accept(email, name, teamname, managername,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -1102,7 +1211,14 @@ def handle_sendemail_request_reject(email, name, teamname, managername,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -1124,7 +1240,14 @@ def handle_sendemail_member_dropped(email, name, teamname, managername,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -1147,7 +1270,14 @@ def handle_sendemail_team_removed(email, name, teamname, managername,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -1169,7 +1299,14 @@ def handle_sendemail_invite_reject(email, name, teamname, managername,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1
@@ -1187,7 +1324,14 @@ def handle_sendemail_invite_accept(email, name, teamname, managername,
'Rowsandall <info@rowsandall.com>', 'Rowsandall <info@rowsandall.com>',
[fullemail]) [fullemail])
res = email.send() if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1 return 1

View File

@@ -105,7 +105,8 @@
are limited to substantial changes in terms and conditions and other are limited to substantial changes in terms and conditions and other
announcements impacting the terms on which you use the site. We will 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 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").
</p> </p>
<p> <p>

View File

@@ -1708,7 +1708,18 @@ def workout_tcxemail_view(request,id=0):
r = getrower(request.user) r = getrower(request.user)
w = get_workout(id) w = get_workout(id)
if (checkworkoutuser(request.user,w)): 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: if tcxfile == 0:
message = "Something went wrong (TCX export) "+tcxmessg message = "Something went wrong (TCX export) "+tcxmessg
messages.error(request,message) 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" successmessage = "The TCX file was sent to you per email"
messages.info(request,successmessage) 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) response = HttpResponseRedirect(url)
else: else:
@@ -1750,6 +1762,16 @@ def workout_gpxemail_view(request,id=0):
message = "" message = ""
successmessage = "" successmessage = ""
r = Rower.objects.get(user=request.user) 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) w = get_workout(id)
if (checkworkoutuser(request.user,w)): if (checkworkoutuser(request.user,w)):
@@ -1787,6 +1809,15 @@ def workout_gpxemail_view(request,id=0):
@login_required() @login_required()
def workouts_summaries_email_view(request): def workouts_summaries_email_view(request):
r = getrower(request.user) 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': if request.method == 'POST':
form = DateRangeForm(request.POST) form = DateRangeForm(request.POST)
@@ -1819,6 +1850,16 @@ def workouts_summaries_email_view(request):
def workout_csvemail_view(request,id=0): def workout_csvemail_view(request,id=0):
message = "" message = ""
r = getrower(request.user) 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) w = get_workout(id)
if (checkworkoutuser(request.user,w)): if (checkworkoutuser(request.user,w)):
@@ -11229,6 +11270,7 @@ def rower_edit_view(request,rowerid=0,message=""):
birthdate = cd['birthdate'] birthdate = cd['birthdate']
showfavoritechartnotes = cd['showfavoritechartnotes'] showfavoritechartnotes = cd['showfavoritechartnotes']
getemailnotifications = cd['getemailnotifications'] getemailnotifications = cd['getemailnotifications']
getimportantemails = cd['getimportantemails']
defaulttimezone=cd['defaulttimezone'] defaulttimezone=cd['defaulttimezone']
u = r.user u = r.user
if u.email != email and len(email): if u.email != email and len(email):
@@ -11247,6 +11289,7 @@ def rower_edit_view(request,rowerid=0,message=""):
r.defaulttimezone=defaulttimezone r.defaulttimezone=defaulttimezone
r.weightcategory = weightcategory r.weightcategory = weightcategory
r.getemailnotifications = getemailnotifications r.getemailnotifications = getemailnotifications
r.getimportantemails = getimportantemails
r.defaultlandingpage = defaultlandingpage r.defaultlandingpage = defaultlandingpage
r.showfavoritechartnotes = showfavoritechartnotes r.showfavoritechartnotes = showfavoritechartnotes
r.sex = sex r.sex = sex
@@ -11587,7 +11630,8 @@ def rower_calcdps_view(request):
r = getrower(request.user) r = getrower(request.user)
ws = [(w.id,w.csvfilename) for w in Workout.objects.filter(user=r)] 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.") messages.info(request,"Your workouts are being updated in the background. You will receive email when this is done.")