diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index d9e6add5..1918d750 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -1597,13 +1597,28 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False): enddatetime ) + # from ws, remove any w where w.workoutsource = 'strava'. For each removal add an error "strava workout not permitted" to the errors list and if there are no workouts left, return 0, comments, errors, 0 + ws2 = [] + for w in ws: + if w.workoutsource != 'strava': + ws2.append(w) + else: + errors.append('Strava workouts are not permitted') + + ws = ws2 + + if len(ws) == 0: + return result, comments, errors, 0 + ids = [w.id for w in ws] ids = list(set(ids)) + if len(ids) > 1 and race.sessiontype in ['test', 'coursetest', 'race', 'indoorrace', 'fastest_time', 'fastest_distance']: # pragma: no cover errors.append('For tests, you can only attach one workout') return result, comments, errors, 0 + if r.birthdate: age = calculate_age(r.birthdate) else: # pragma: no cover @@ -1759,6 +1774,19 @@ def add_workout_indoorrace(ws, race, r, recordid=0, doregister=False): enddatetime ) + # from ws, remove any w where w.workoutsource = 'strava'. For each removal add an error "strava workout not permitted" to the errors list and if there are no workouts left, return 0, comments, errors, 0 + ws2 = [] + for w in ws: + if w.workoutsource != 'strava': + ws2.append(w) + else: + errors.append('Strava workouts are not permitted') + + ws = ws2 + + if len(ws) == 0: + return result, comments, errors, 0 + # check if all sessions have same date dates = [w.date for w in ws] if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge', 'cycletarget']: # pragma: no cover @@ -1906,6 +1934,19 @@ def add_workout_race(ws, race, r, splitsecond=0, recordid=0, doregister=False): enddatetime ) + # from ws, remove any w where w.workoutsource = 'strava'. For each removal add an error "strava workout not permitted" to the errors list and if there are no workouts left, return 0, comments, errors, 0 + ws2 = [] + for w in ws: + if w.workoutsource != 'strava': + ws2.append(w) + else: + errors.append('Strava workouts are not permitted') + + ws = ws2 + + if len(ws) == 0: + return result, comments, errors, 0 + # check if all sessions have same date dates = [w.date for w in ws] if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge', 'cycletarget']: # pragma: no cover diff --git a/rowers/rower_rules.py b/rowers/rower_rules.py index ed5cd2dd..68529023 100644 --- a/rowers/rower_rules.py +++ b/rowers/rower_rules.py @@ -463,6 +463,9 @@ def is_workout_user(user, workout): # check if user is in same team as owner of workout +@rules.predicate +def workout_is_strava(workout): + return workout.workoutsource == 'strava' @rules.predicate def is_workout_team(user, workout): diff --git a/rowers/tests/test_api.py b/rowers/tests/test_api.py index 649bca2f..83b2ba82 100644 --- a/rowers/tests/test_api.py +++ b/rowers/tests/test_api.py @@ -441,6 +441,12 @@ class StravaPrivacy(TestCase): self.assertEqual(response.status_code,200) + # count number of workouts by counting the number of occurences of '