diff --git a/rowers/forms.py b/rowers/forms.py index d0e78a23..27deb56f 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -389,18 +389,26 @@ class UploadOptionsForm(forms.Form): super(UploadOptionsForm, self).__init__(*args, **kwargs) r = Rower.objects.get(user=self.request.user) races = VirtualRace.objects.filter( - registration_closure__gt=timezone.now(), - sessiontype='indoorrace') + registration_closure__gt=timezone.now()) registrations = IndoorVirtualRaceResult.objects.filter( race__in = races, userid = r.id) + registrations2 = VirtualRaceResult.objects.filter( + race__in = races, + userid = r.id, + ) + raceids = [r.race.id for r in registrations] + raceids2 = [r.race.id for r in registrations2] + + raceids = raceids+raceids2 races = VirtualRace.objects.filter( id__in=raceids ) + if races: self.fields['submitrace'].queryset = races else: @@ -409,6 +417,8 @@ class UploadOptionsForm(forms.Form): if int(raceid) in raceids: self.fields['submitrace'].initial = VirtualRace.objects.get(id=raceid) + + # The form to indicate additional actions to be performed immediately # after a successful upload. This version allows the Team manager to select # a team member diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 63286c21..4c859b65 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -1472,7 +1472,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0): errors.append('For tests and training sessions, selected workouts must all be done on the same date') return result,comments,errors,0 - if ws.count()>1 and race.sessiontype == 'test': + if len(ws)>1 and race.sessiontype == 'test': errors.append('For tests, you can only attach one workout') return result,comments,errors,0 @@ -1553,6 +1553,8 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0): job = myqueue(queue,handle_check_race_course,ws[0].csvfilename, ws[0].id,race.course.id,record.id,splitsecond=splitsecond) + + add_workouts_plannedsession(ws,race,r) diff --git a/rowers/templates/menu_racing.html b/rowers/templates/menu_racing.html index 058a8cab..c1eb9178 100644 --- a/rowers/templates/menu_racing.html +++ b/rowers/templates/menu_racing.html @@ -51,7 +51,7 @@  Submit Workout
  • - +  Upload your Challenge result
  • diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 7a0c6d3a..6e851339 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -4965,26 +4965,46 @@ def workout_upload_view(request, messages.error(request,message) if race and race_can_submit(r,race): - records = IndoorVirtualRaceResult.objects.filter( - race=race, - userid=r.id - ) - - if records: - - result,comments,errors,jobid = add_workout_indoorrace( - [w],race,r,recordid=records[0].id + if race.sessiontype == 'indoorrace': + records = IndoorVirtualRaceResult.objects.filter( + race=race, + userid=r.id ) - if result: - messages.info( - request, - "We have submitted your workout to the race") + if records: - for c in comments: - messages.info(request,c) - for er in errors: - messages.error(request,er) + result,comments,errors,jobid = add_workout_indoorrace( + [w],race,r,recordid=records[0].id + ) + + if result: + messages.info( + request, + "We have submitted your workout to the race") + + for c in comments: + messages.info(request,c) + for er in errors: + messages.error(request,er) + if race.sessiontype == 'race': + records = VirtualRaceResult.objects.filter( + race=race,userid=r.id + ) + + + if records: + result,comments,errors,jobid = add_workout_race( + [w], race,r,recordid=records[0].id + ) + if result: + messages.info( + request, + "We have submitted your workout to the race") + + for c in comments: + messages.info(request,c) + for er in errors: + messages.error(request,er) if landingpage != 'workout_upload_view':