Private
Public Access
1
0

Merge branch 'develop' into feature/teamcompare

This commit is contained in:
Sander Roosendaal
2017-02-19 10:09:20 +01:00
4 changed files with 23 additions and 8 deletions

View File

@@ -229,6 +229,7 @@ def timedeltaconv(x):
def save_workout_database(f2,r,dosmooth=True,workouttype='rower', def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
dosummary=True,title='Workout', dosummary=True,title='Workout',
notes='',totaldist=0,totaltime=0, notes='',totaldist=0,totaltime=0,
summary='',
makeprivate=False): makeprivate=False):
message = None message = None
powerperc = 100*np.array([r.pw_ut2, powerperc = 100*np.array([r.pw_ut2,
@@ -481,6 +482,7 @@ def new_workout_from_file(r,f2,
workouttype=workouttype, workouttype=workouttype,
makeprivate=makeprivate, makeprivate=makeprivate,
dosummary=dosummary, dosummary=dosummary,
summary=summary,
title=title) title=title)
return (id,message,f2) return (id,message,f2)

View File

@@ -233,12 +233,20 @@ def handle_stravaexport(f2,workoutname,stravatoken,description=''):
client = stravalib.Client(access_token=stravatoken) client = stravalib.Client(access_token=stravatoken)
act = client.upload_activity(f2,'tcx',name=workoutname) 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 # 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)

View File

@@ -197,6 +197,8 @@ def create_invite(team,manager,user=None,email=''):
user = User.objects.get(rower=r2) user = User.objects.get(rower=r2)
except Rower.DoesNotExist: except Rower.DoesNotExist:
user=None 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: if count_club_members(team.manager)+count_invites(team.manager) < r.clubsize:
codes = [i.code for i in TeamInvite.objects.all()] codes = [i.code for i in TeamInvite.objects.all()]

View File

@@ -207,8 +207,11 @@ def iscoachmember(user):
# Check if a user is a Pro member # Check if a user is a Pro member
def ispromember(user): def ispromember(user):
r = Rower.objects.get(user=user) if not user.is_anonymous():
result = user.is_authenticated() and (r.rowerplan=='pro' or r.rowerplan=='coach') r = Rower.objects.get(user=user)
result = user.is_authenticated() and (r.rowerplan=='pro' or r.rowerplan=='coach')
else:
result = False
return result return result
# User registration # User registration
@@ -800,11 +803,11 @@ def workout_strava_upload_view(request,id=0):
tcxfile = stravastuff.createstravaworkoutdata(w) tcxfile = stravastuff.createstravaworkoutdata(w)
if tcxfile: if tcxfile:
with open(tcxfile,'rb') as f: with open(tcxfile,'rb') as f:
res = stravastuff.handle_stravaexport(f,w.name, res,mes = stravastuff.handle_stravaexport(f,w.name,
r.stravatoken, r.stravatoken,
description=w.notes) description=w.notes)
if res==0: if res==0:
message = "Strava Upload error: %s" % e message = mes
w.uploadedtostrava = -1 w.uploadedtostrava = -1
w.save() w.save()
os.remove(tcxfile) os.remove(tcxfile)
@@ -820,7 +823,7 @@ def workout_strava_upload_view(request,id=0):
w.save() w.save()
os.remove(tcxfile) os.remove(tcxfile)
url = "/rowers/workout/"+str(w.id)+"/edit" url = "/rowers/workout/"+str(w.id)+"/edit"
successmessage = 'Workout sent to Strava.' successmessage = mes
except: except:
with open("media/stravaerrors.log","a") as errorlog: with open("media/stravaerrors.log","a") as errorlog:
errorstring = str(sys.exc_info()[0]) errorstring = str(sys.exc_info()[0])