From 35e853aea11620e64c324056063f0f8f8e113dd3 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 19 Feb 2017 09:29:00 +0100 Subject: [PATCH] hotfix fit functionality, strava timeout, team invite --- rowers/dataprep.py | 2 ++ rowers/stravastuff.py | 8 ++++++-- rowers/teams.py | 2 ++ rowers/views.py | 6 +++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 434068c9..d212f517 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -229,6 +229,7 @@ def timedeltaconv(x): def save_workout_database(f2,r,dosmooth=True,workouttype='rower', dosummary=True,title='Workout', notes='',totaldist=0,totaltime=0, + summary='', makeprivate=False): message = None powerperc = 100*np.array([r.pw_ut2, @@ -481,6 +482,7 @@ def new_workout_from_file(r,f2, workouttype=workouttype, makeprivate=makeprivate, dosummary=dosummary, + summary=summary, title=title) return (id,message,f2) diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index 7c23c596..144787f2 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -235,14 +235,18 @@ def handle_stravaexport(f2,workoutname,stravatoken,description=''): act = client.upload_activity(f2,'tcx',name=workoutname) try: res = act.wait(poll_interval=5.0) + message = 'Workout successfully synchronized to Strava' except: res = 0 # description doesn't work yet. Have to wait for stravalib to update - act = client.update_activity(res.id,activity_type='Rowing',description=description) + if res: + act = client.update_activity(res.id,activity_type='Rowing',description=description) + else: + message = 'Strava upload timed out.' - return res.id + return (res.id,message) diff --git a/rowers/teams.py b/rowers/teams.py index 9891facb..dcf7371b 100644 --- a/rowers/teams.py +++ b/rowers/teams.py @@ -197,6 +197,8 @@ def create_invite(team,manager,user=None,email=''): user = User.objects.get(rower=r2) except Rower.DoesNotExist: user=None + except Rower.MultipleObjectsReturned: + return (0,'There is more than one user with that email address') if count_club_members(team.manager)+count_invites(team.manager) < r.clubsize: codes = [i.code for i in TeamInvite.objects.all()] diff --git a/rowers/views.py b/rowers/views.py index 5011e1d0..c0b48523 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -803,11 +803,11 @@ def workout_strava_upload_view(request,id=0): tcxfile = stravastuff.createstravaworkoutdata(w) if tcxfile: with open(tcxfile,'rb') as f: - res = stravastuff.handle_stravaexport(f,w.name, + res,mes = stravastuff.handle_stravaexport(f,w.name, r.stravatoken, description=w.notes) if res==0: - message = "Strava Upload error: %s" % e + message = mes w.uploadedtostrava = -1 w.save() os.remove(tcxfile) @@ -823,7 +823,7 @@ def workout_strava_upload_view(request,id=0): w.save() os.remove(tcxfile) url = "/rowers/workout/"+str(w.id)+"/edit" - successmessage = 'Workout sent to Strava.' + successmessage = mes except: with open("media/stravaerrors.log","a") as errorlog: errorstring = str(sys.exc_info()[0])