Private
Public Access
1
0

Merge branch 'develop' into feature/opaqueid

This commit is contained in:
Sander Roosendaal
2019-01-31 18:25:25 +01:00
2 changed files with 48 additions and 122 deletions

8
.gitignore vendored
View File

@@ -26,8 +26,9 @@ conftest.py
# temporary test files
/rowers/tests/testdata/temp
/rowers/tests/testdate/testdata.csv.gz
/rowers/tests/testdate/testdata.tcx
/rowers/tests/testdata/testdata.csv.gz
/rowers/tests/testdata/testdata.tcx
# Python egg metadata, regenerated from source files by setuptools.
*.egg-info
@@ -48,3 +49,6 @@ manage.py
# secrets
config.yaml
# test data

View File

@@ -1871,63 +1871,32 @@ def add_workout_from_strokedata(user,importid,data,strokedata,
def workout_tcxemail_view(request,id=0):
if id:
id = encoder.decode_hex(id)
message = ""
successmessage = ""
r = getrower(request.user)
w = get_workout(id)
if (checkworkoutuser(request.user,w)):
if r.emailbounced:
message = "Please check your email address first. Email to this address bounced."
messages.error(request, message)
url = reverse(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(id)
})
return HttpResponseRedirect(url)
if not checkworkoutuser(request.user,w):
raise PermissionDenied("Access denied")
row = rdata(w.csvfilename)
tcxfile,tcxmessg = stravastuff.createstravaworkoutdata(w,dozip=False)
if tcxfile == 0:
message = "Something went wrong (TCX export) "+tcxmessg
messages.error(request,message)
url = reverse(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(id)
})
return HttpResponseRedirect(url)
if tcxfile:
res = myqueue(queuehigh,handle_sendemailtcx,
r.user.first_name,
r.user.last_name,
r.user.email,
tcxfile,
emailbounced = r.emailbounced
)
code = str(uuid4())
tcxfilename = code+'.tcx'
successmessage = "The TCX file was sent to you per email"
messages.info(request,successmessage)
row.exporttotcx(tcxfilename)
url = reverse(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(id)
})
response = HttpResponseRedirect(url)
with open(tcxfilename,'r') as f:
response = HttpResponse(f)
response['Content-Disposition'] = 'attachment; filename="%s"' % tcxfilename
response['Content-Type'] = 'application/octet-stream'
else:
message = "You are not allowed to export this workout"
messages.error(request,message)
url = reverse(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(id)
})
response = HttpResponseRedirect(url)
os.remove(tcxfilename)
return response
@login_required()
def plannedsessions_icsemail_view(request,userid=0):
r = getrequestrower(request,userid=userid)
@@ -2025,52 +1994,27 @@ def course_kmldownload_view(request,id=0):
def workout_gpxemail_view(request,id=0):
if id != 0:
id = encoder.decode_hex(id)
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)
url = reverse(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(id)
})
return HttpResponseRedirect(url)
r = getrower(request.user)
w = get_workout(id)
if (checkworkoutuser(request.user,w)):
filename = w.csvfilename
row = rdata(filename)
gpxfilename = filename[:-4]+'.gpx'
row.exporttogpx(gpxfilename)
res = myqueue(queuehigh,handle_sendemailtcx,
r.user.first_name,
r.user.last_name,
r.user.email,gpxfilename,
emailbounced = r.emailbounced
)
if not checkworkoutuser(request.user,w):
raise PermissionDenied("Access denied")
successmessage = "The GPX file was sent to you per email"
messages.info(request,successmessage)
url = reverse(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(id)
})
response = HttpResponseRedirect(url)
row = rdata(w.csvfilename)
code = str(uuid4())
gpxfilename = code+'.gpx'
row.exporttogpx(gpxfilename)
with open(gpxfilename,'r') as f:
response = HttpResponse(f)
response['Content-Disposition'] = 'attachment; filename="%s"' % gpxfilename
response['Content-Type'] = 'application/octet-stream'
os.remove(gpxfilename)
else:
message = "You are not allowed to export this workout"
messages.error(request,message)
url = reverse(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(w.id),
})
response = HttpResponseRedirect(url)
return response
# Get Workout summary CSV file
@@ -2117,46 +2061,24 @@ def workouts_summaries_email_view(request):
def workout_csvemail_view(request,id=0):
if id:
id = encoder.decode_hex(id)
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(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(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,
emailbounced = r.emailbounced
)
if not checkworkoutuser(request.user,w):
raise PermissionDenied("Access denied")
rowdata = rdata(w.csvfilename)
code = str(uuid4())
filename = code+'.csv'
response = HttpResponse(rowdata.df.to_csv())
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
response['Content-Type'] = 'application/octet-stream'
successmessage = "The CSV file was sent to you per email"
messages.info(request,successmessage)
url = reverse(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(w.id),
})
response = HttpResponseRedirect(url)
else:
message = "You are not allowed to export this workout"
messages.error(request,message)
url = reverse(r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(w.id),
})
response = HttpResponseRedirect(url)
return response
# Get Workout CSV file and send it to user's email address
@login_required()