From 76c9666b566669c3c0510a23511ba26cc39ce6b3 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 5 Jan 2017 21:06:50 +0100 Subject: [PATCH] fix Strava upload --- rowers/views.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/rowers/views.py b/rowers/views.py index 698643ba..1ec36004 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -934,34 +934,31 @@ def workout_strava_upload_view(request,id=0): if (checkworkoutuser(request.user,w)): try: tcxfile = stravastuff.createstravaworkoutdata(w) - except: - with open("media/stravaerrors.log","a") as errorlog: - errorstring = str(sys.exc_info()[0]) - timestr = time.strftime("%Y%m%d-%H%M%S") - errorlog.write(timestr+errorstring+"\r\n") - errorlog.write("views.py line 946\r\n") - try: + with open(tcxfile,'rb') as f: try: res = stravastuff.handle_stravaexport(f,w.name, r.stravatoken, description=w.notes) - except: + w.uploadedtostrava = res + w.save() + os.remove(tcxfile) + url = "/rowers/workout/"+str(w.id)+"/edit" + successmessage = 'Workout sent to Strava.' + except: with open("media/stravaerrors.log","a") as errorlog: errorstring = str(sys.exc_info()[0]) - timestr = time.strftime("%Y%m%d-%H%M%S") + timestr = strftime("%Y%m%d-%H%M%S") errorlog.write(timestr+errorstring+"\r\n") errorlog.write("views.py line 946\r\n") + message = 'Error: '+errorstring + - w.uploadedtostrava = res - w.save() - os.remove(tcxfile) - url = "/rowers/workout/"+str(w.id)+"/edit" - successmessage = 'Workout sent to Strava.' url = reverse(workout_export_view, kwargs = { 'id':str(w.id), + 'message':message, } ) response = HttpResponseRedirect(url) @@ -973,7 +970,6 @@ def workout_strava_upload_view(request,id=0): url = reverse(workout_export_view, kwargs = { 'id':str(w.id), - 'message':message, }) response = HttpResponseRedirect(url) # except TimeoutExceeded as e: @@ -1014,7 +1010,7 @@ def workout_c2_upload_view(request,id=0): message = "Unexpected Error: "+str(sys.exc_info()[0]) with open("media/c2errors.log","a") as errorlog: errorstring = str(sys.exc_info()[0]) - timestr = time.strftime("%Y%m%d-%H%M%S") + timestr = strftime("%Y%m%d-%H%M%S") errorlog.write(timestr+errorstring+"\r\n") # check for duplicate error first @@ -1034,7 +1030,7 @@ def workout_c2_upload_view(request,id=0): message = "Something went wrong in workout_c2_upload_view. Response code 200/201 but C2 sync failed: "+response.text with open("media/c2errors.log","a") as errorlog: errorstring = str(sys.exc_info()[0]) - timestr = time.strftime("%Y%m%d-%H%M%S") + timestr = strftime("%Y%m%d-%H%M%S") errorlog.write(timestr+errorstring+"\r\n") @@ -1043,7 +1039,7 @@ def workout_c2_upload_view(request,id=0): message = "Something went wrong in workout_c2_upload_view. C2 sync failed." with open("media/c2errors.log","a") as errorlog: errorstring = str(sys.exc_info()[0]) - timestr = time.strftime("%Y%m%d-%H%M%S") + timestr = strftime("%Y%m%d-%H%M%S") errorlog.write(timestr+errorstring+"\r\n") else: