Private
Public Access
1
0

Merge branch 'feature/importantemail' into develop

This commit is contained in:
Sander Roosendaal
2018-03-18 10:25:43 +01:00
6 changed files with 273 additions and 73 deletions

View File

@@ -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)

View File

@@ -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']

View File

@@ -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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[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 <info@rowsandall.com>',
[fullemail])
res = email.send()
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
return 1

View File

@@ -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").
</p>
<p>

View File

@@ -356,6 +356,7 @@ urlpatterns = [
url(r'^me/invitation/(?P<id>\d+)/reject$',views.invitation_reject_view),
url(r'^me/invitation/(?P<id>\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<id>\d+)/revoke',views.request_revoke_view),
url(r'^me/request/(?P<id>\d+)/reject',views.request_reject_view),

View File

@@ -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):
@@ -1708,7 +1715,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)
@@ -1722,15 +1740,18 @@ 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)
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 +1771,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)):
@@ -1760,7 +1791,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"
@@ -1787,6 +1820,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)
@@ -1803,7 +1845,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()
@@ -1819,13 +1863,25 @@ 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)):
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)
@@ -7135,6 +7191,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:
@@ -8537,12 +8594,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,
@@ -8553,7 +8613,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})
@@ -10336,7 +10398,9 @@ def team_workout_upload_view(request,message="",
handle_zip_file,
r.user.email,
t,
f2)
f2,
emailbounced = r.emailbounced
)
messages.info(
request,
@@ -11229,6 +11293,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 +11312,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 +11653,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.")