diff --git a/requirements.txt b/requirements.txt index a237c95a..25b00df6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,8 @@ billiard==3.6.0.0 bleach==3.1.0 bokeh==1.0.4 boto==2.49.0 +boto3==1.14.7 +botocore==1.17.7 braintree==3.55.0 cairocffi==1.0.2 celery==4.3.0 @@ -53,7 +55,7 @@ django-rest-framework==0.1.0 django-rest-swagger==2.2.0 django-rq==1.3.1 django-rq-dashboard==0.3.3 -django-ses==0.8.10 +django-ses==1.0.0 django-shell-plus==1.1.7 django-social-share==1.3.2 django-suit==0.2.26 @@ -96,6 +98,7 @@ itypes==1.1.0 jedi==0.13.3 jeepney==0.4 Jinja2==2.10 +jmespath==0.10.0 json5==0.8.5 jsonschema==3.0.1 jupyter==1.0.0 @@ -125,7 +128,7 @@ newrelic==5.2.1.129 nose==1.3.7 nose-parameterized==0.6.0 notebook==5.7.6 -numba==0.46.0 +numba==0.50.0 numpy==1.18.5 oauth2==1.9.0.post1 oauthlib==3.0.1 @@ -179,6 +182,7 @@ rowingdata==2.9.1 rowingphysics==0.5.0 rq==0.13.0 rules==2.1 +s3transfer==0.3.3 scipy==1.2.1 SecretStorage==3.1.1 Send2Trash==1.5.0 diff --git a/rowers/forms.py b/rowers/forms.py index 3dc3a222..42987cb4 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -124,7 +124,7 @@ class EmailForm(forms.Form): subject = forms.CharField(max_length=255) message = forms.CharField(widget=forms.Textarea()) - + disqualificationreasons = ( ('noimage','No monitor screenshot or data evidence was included'), @@ -386,7 +386,7 @@ class UploadOptionsForm(forms.Form): makeprivate = forms.BooleanField(initial=False,required=False, label='Make Workout Private') - submitrace = forms.ModelChoiceField(queryset=VirtualRace.objects.all(), + submitrace = forms.ChoiceField( label='Submit as challenge Result', required=False) @@ -404,6 +404,7 @@ class UploadOptionsForm(forms.Form): r = Rower.objects.get(user=self.request.user) races = VirtualRace.objects.filter( registration_closure__gt=timezone.now()) + registrations = IndoorVirtualRaceResult.objects.filter( race__in = races, userid = r.id) @@ -413,25 +414,27 @@ class UploadOptionsForm(forms.Form): userid = r.id, ) - raceids = [r.race.id for r in registrations] - raceids2 = [r.race.id for r in registrations2] + choices1 = [(r.id,str(r)) for r in registrations] + choices2 = [(r.id,str(r)) for r in registrations2] + choices3 = [(0,'---')] - raceids = raceids+raceids2 + choices = choices3+choices1+choices2 - races = VirtualRace.objects.filter( - id__in=raceids - ) + if int(raceid) in [r.id for r in races]: + therace = VirtualRace.objects.get(id=raceid) + if therace.sessiontype == 'race': + registrations = VirtualRaceResult.objects.filter(race=therace,userid=r.id) + else: + registrations = IndoorVirtualRaceResult.objects.filter(race=therace,userid=r.id) + choices = [(r.id,str(r)) for r in registrations] + choices = [(0,'---')]+choices if races: - self.fields['submitrace'].queryset = races + self.fields['submitrace'].choices = choices else: del self.fields['submitrace'] - 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 diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index a9be6a3e..674b5fe8 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -1343,6 +1343,7 @@ def remove_rower_race(r,race,recordid=None): # Low Level functions - to be called by higher level methods def add_workout_indoorrace(ws,race,r,recordid=0): + print('aap') result = 0 comments = [] errors = [] @@ -1402,6 +1403,8 @@ def add_workout_indoorrace(ws,race,r,recordid=0): workoutid = ws[0].id ) + print(record,records) + if not record: errors.append("Couldn't find this entry") return result,comments,errors,0 @@ -1471,7 +1474,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0): return result,comments,errors,0 -def add_workout_race(ws,race,r,splitsecond=0,recordid=0): +def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False): result = 0 comments = [] errors = [] diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 43bea2b4..79b8f1ea 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -4909,7 +4909,7 @@ def workout_upload_view(request, notes = form.cleaned_data['notes'] offline = form.cleaned_data['offline'] - race = None + registrationid = 0 if optionsform.is_valid(): make_plot = optionsform.cleaned_data['make_plot'] plottype = optionsform.cleaned_data['plottype'] @@ -4923,9 +4923,9 @@ def workout_upload_view(request, landingpage = optionsform.cleaned_data['landingpage'] try: - race = optionsform.cleaned_data['submitrace'] + registrationid = optionsform.cleaned_data['submitrace'] except KeyError: - race = None + registrationid = 0 uploadoptions = { 'makeprivate':makeprivate, @@ -5113,17 +5113,60 @@ def workout_upload_view(request, else: messages.error(request,message) - if race and race_can_submit(r,race): - if race.sessiontype == 'indoorrace': - records = IndoorVirtualRaceResult.objects.filter( - race=race, - userid=r.id + if int(registrationid) < 0: + race = VirtualRace.Objects.get(id=-int(registrationid)) + if race.sessiontype == 'race': + race = registrations[0].race + result,comments,errors,jobid = add_workout_race( + [w], race,r, + ) + 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) + elif race.sessiontype == 'indoorrace': + race = registrations[0].race + result,comments,errors,jobid = add_workout_indoorrace( + [w],race,r, ) - if records: + 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 int(registrationid)>0: + races = VirtualRace.objects.filter( + registration_closure__gt=timezone.now() + ) + registrations = IndoorVirtualRaceResult.objects.filter( + race__in = races, + id=registrationid, + userid = r.id, + ) + registrations2 = VirtualRaceResult.objects.filter( + race__in = races, + id=registrationid, + userid=r.id, + ) + + if int(registrationid) in [r.id for r in registrations]: + # indoor race + registrations = registrations.filter(id=registrationid) + if registrations: + race = registrations[0].race result,comments,errors,jobid = add_workout_indoorrace( - [w],race,r,recordid=records[0].id + [w],race,r,recordid=registrations[0].id ) if result: @@ -5135,15 +5178,15 @@ def workout_upload_view(request, 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: + if int(registrationid) in [r.id for r in registrations2]: + # race + registrations = registrations2.filter(id=registrationid) + if registrations: + race = registrations[0].race result,comments,errors,jobid = add_workout_race( - [w], race,r,recordid=records[0].id + [w], race,r,recordid=registrations[0].id ) if result: messages.info( @@ -5156,6 +5199,7 @@ def workout_upload_view(request, messages.error(request,er) + if landingpage != 'workout_upload_view': url = reverse(landingpage, kwargs = {