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 0987d2cb..144787f2 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -233,12 +233,20 @@ def handle_stravaexport(f2,workoutname,stravatoken,description=''): client = stravalib.Client(access_token=stravatoken) act = client.upload_activity(f2,'tcx',name=workoutname) - res = act.wait(poll_interval=5.0) + 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 b66d54a6..c264a9f3 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -207,8 +207,11 @@ def iscoachmember(user): # Check if a user is a Pro member def ispromember(user): - r = Rower.objects.get(user=user) - result = user.is_authenticated() and (r.rowerplan=='pro' or r.rowerplan=='coach') + if not user.is_anonymous(): + r = Rower.objects.get(user=user) + result = user.is_authenticated() and (r.rowerplan=='pro' or r.rowerplan=='coach') + else: + result = False return result # User registration @@ -800,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) @@ -820,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])