diff --git a/rowers/dataprep.py b/rowers/dataprep.py index e2e040d2..a5d9d299 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -406,7 +406,7 @@ def nicepaceformat(values): # Convert seconds to a Time Delta value, replacing NaN with a 5:50 pace def timedeltaconv(x): - if np.isfinite(x) and x != 0: + if np.isfinite(x) and x != 0 and x>0 and x<175000: dt = datetime.timedelta(seconds=x) else: dt = datetime.timedelta(seconds=350.) @@ -571,16 +571,17 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower', workoutstartdatetime = thetimezone.localize(row.rowdatetime).astimezone(utc) if makeprivate: - privacy = 'private' + privacy = 'hidden' else: privacy = 'visible' - # check for duplicate start times + # check for duplicate start times and duration ws = Workout.objects.filter(startdatetime=workoutstartdatetime, + duration=duration, user=r) if (len(ws) != 0): message = "Warning: This workout probably already exists in the database" - privacy = 'private' + privacy = 'hidden' # checking for inf values totaldist = np.nan_to_num(totaldist) @@ -868,13 +869,13 @@ def split_workout(r,parent,splitsecond,splitmode): ids = [] if 'keep first' in splitmode: - if 'secondprivate' in splitmode: + if 'firstprivate' in splitmode: setprivate = True else: setprivate = False id,message = new_workout_from_df(r,data1, - title=parent.name+' First Part', + title=parent.name+' (1)', parent=parent, setprivate=setprivate) messages.append(message) @@ -891,7 +892,7 @@ def split_workout(r,parent,splitsecond,splitmode): dt = datetime.timedelta(seconds=splitsecond) id,message = new_workout_from_df(r,data2, - title=parent.name+' Second Part', + title=parent.name+' (2)', parent=parent, setprivate=setprivate, dt=dt) @@ -930,7 +931,11 @@ def new_workout_from_df(r,df, workouttype = parent.workouttype notes=parent.notes summary=parent.summary - makeprivate=parent.privacy + if parent.privacy == 'hidden': + makeprivate=True + else: + makeprivate=False + startdatetime=parent.startdatetime+dt else: oarlength = 2.89 @@ -943,6 +948,7 @@ def new_workout_from_df(r,df, if setprivate: makeprivate=True + timestr = strftime("%Y%m%d-%H%M%S") diff --git a/rowers/views.py b/rowers/views.py index b4bab4f6..49e17ed2 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -7947,7 +7947,7 @@ def workout_split_view(request,id=id): except Workout.DoesNotExist: raise Http404("Workout doesn't exist") - r = getrower(request.user) + r = row.user if request.method == 'POST': form = WorkoutSplitForm(request.POST) @@ -7962,7 +7962,24 @@ def workout_split_view(request,id=id): for message in mesgs: messages.info(request,message) - url = reverse(workouts_view) + + if request.user == r: + url = reverse(workouts_view) + else: + mgrids = [team.id for team in Team.objects.filter(manager=request.user)] + rwrids = [team.id for team in r.team.all()] + teamids = list(set(mgrids) & set(rwrids)) + if len(teamids) > 0: + teamid = teamids[0] + + url = reverse(workouts_view, + kwargs={ + 'teamid':int(teamid), + } + ) + else: + url = reverse(workouts_view) + qdict = {'q':row.name} url+='?'+urllib.urlencode(qdict)