adding race selector to workout upload
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
from django import forms
|
||||
from django.contrib.admin.widgets import FilteredSelectMultiple
|
||||
from rowers.models import Workout,Rower,Team,PlannedSession,GeoCourse
|
||||
from rowers.models import (
|
||||
Workout,Rower,Team,PlannedSession,GeoCourse,
|
||||
VirtualRace,VirtualRaceResult,IndoorVirtualRaceResult
|
||||
)
|
||||
from rowers.rows import validate_file_extension,must_be_csv,validate_image_extension,validate_kml
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
@@ -16,6 +19,7 @@ from utils import landingpages
|
||||
from metrics import axes
|
||||
|
||||
|
||||
|
||||
# login form
|
||||
class LoginForm(forms.Form):
|
||||
username = forms.CharField()
|
||||
@@ -254,6 +258,10 @@ class UploadOptionsForm(forms.Form):
|
||||
makeprivate = forms.BooleanField(initial=False,required=False,
|
||||
label='Make Workout Private')
|
||||
|
||||
submitrace = forms.ModelChoiceField(queryset=VirtualRace.objects.all(),
|
||||
label='Submit as Race Result',
|
||||
required=False)
|
||||
|
||||
landingpage = forms.ChoiceField(choices=nextpages,
|
||||
initial='workout_edit_view',
|
||||
label='After Upload, go to')
|
||||
@@ -261,6 +269,28 @@ class UploadOptionsForm(forms.Form):
|
||||
class Meta:
|
||||
fields = ['make_plot','plottype','upload_toc2','makeprivate']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.request = kwargs.pop('request',None)
|
||||
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')
|
||||
registrations = IndoorVirtualRaceResult.objects.filter(
|
||||
race__in = races,
|
||||
userid = r.id)
|
||||
|
||||
raceids = [r.race.id for r in registrations]
|
||||
|
||||
races = VirtualRace.objects.filter(
|
||||
id__in=raceids
|
||||
)
|
||||
|
||||
if races:
|
||||
self.fields['submitrace'].queryset = races
|
||||
else:
|
||||
del self.fields['submitrace']
|
||||
|
||||
# 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
|
||||
|
||||
@@ -1006,6 +1006,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
|
||||
record.duration = ws[0].duration
|
||||
|
||||
|
||||
|
||||
if ws[0].weightcategory != record.weightcategory:
|
||||
errors.append('Your workout weight category did not match the weight category you registered')
|
||||
return 0,comments, errors,0
|
||||
@@ -1029,7 +1030,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
|
||||
record.coursecompleted = True
|
||||
record.workoutid = ws[0].id
|
||||
record.save()
|
||||
|
||||
|
||||
add_workouts_plannedsession(ws,race,r)
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<i class="fas fa-file-plus fa-fw"></i> Submit Workout</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/rowers/upload">
|
||||
<a href="/rowers/workout/upload">
|
||||
<i class="fas fa-file-upload fa-fw"></i> Upload your race result
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -37,10 +37,10 @@
|
||||
{% if rower %}
|
||||
{% if race|can_register:rower %}
|
||||
<a class="white dot" href="/rowers/virtualevent/{{ race.id }}"> </a>
|
||||
{% elif race|can_submit:rower %}
|
||||
<a class="orange dot" href="/rowers/virtualevent/{{ race.id }}"> </a>
|
||||
{% elif race|race_complete:rower %}
|
||||
<a class="green dot" href="/rowers/virtualevent/{{ race.id }}"> </a>
|
||||
{% elif race|can_submit:rower %}
|
||||
<a class="orange dot" href="/rowers/virtualevent/{{ race.id }}"> </a>
|
||||
{% elif race|future_registered:rower %}
|
||||
<a class="orange dot" href="/rowers/virtualevent/{{ race.id }}"> </a>
|
||||
{% elif race|past_not_registered:rower %}
|
||||
|
||||
165
rowers/views.py
165
rowers/views.py
@@ -11462,7 +11462,7 @@ def workout_upload_view(request,
|
||||
response = {}
|
||||
if request.method == 'POST':
|
||||
form = DocumentsForm(request.POST,request.FILES)
|
||||
optionsform = UploadOptionsForm(request.POST)
|
||||
optionsform = UploadOptionsForm(request.POST,request=request)
|
||||
|
||||
if form.is_valid():
|
||||
# f = request.FILES['file']
|
||||
@@ -11503,6 +11503,11 @@ def workout_upload_view(request,
|
||||
makeprivate = optionsform.cleaned_data['makeprivate']
|
||||
landingpage = optionsform.cleaned_data['landingpage']
|
||||
|
||||
try:
|
||||
race = optionsform.cleaned_data['submitrace']
|
||||
except KeyError:
|
||||
race = None
|
||||
|
||||
uploadoptions = {
|
||||
'makeprivate':makeprivate,
|
||||
'make_plot':make_plot,
|
||||
@@ -11688,6 +11693,28 @@ def workout_upload_view(request,
|
||||
else:
|
||||
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 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':
|
||||
url = reverse(landingpage,
|
||||
@@ -11736,7 +11763,8 @@ def workout_upload_view(request,
|
||||
uploadoptions['upload_to_MapMyFitness'] = True
|
||||
|
||||
form = DocumentsForm(initial=docformoptions)
|
||||
optionsform = UploadOptionsForm(initial=uploadoptions)
|
||||
optionsform = UploadOptionsForm(initial=uploadoptions,
|
||||
request=request)
|
||||
return render(request, 'document_form.html',
|
||||
{'form':form,
|
||||
'active':'nav-workouts',
|
||||
@@ -16122,11 +16150,32 @@ def virtualevent_disqualify_view(request,raceid=0,recordid=0):
|
||||
},
|
||||
]
|
||||
|
||||
buttons = []
|
||||
|
||||
if not request.user.is_anonymous():
|
||||
if race_can_register(r,race):
|
||||
buttons += ['registerbutton']
|
||||
|
||||
if race_can_adddiscipline(r,race):
|
||||
buttons += ['adddisciplinebutton']
|
||||
|
||||
if race_can_submit(r,race):
|
||||
buttons += ['submitbutton']
|
||||
|
||||
if race_can_resubmit(r,race):
|
||||
buttons += ['resubmitbutton']
|
||||
|
||||
if race_can_withdraw(r,race):
|
||||
buttons += ['withdrawbutton']
|
||||
|
||||
if race_can_edit(r,race):
|
||||
buttons += ['editbutton']
|
||||
|
||||
return render(request,"disqualification_view.html",
|
||||
{'workout':workout,
|
||||
'active':'nav-racing',
|
||||
'graphs':g,
|
||||
'buttons':buttons,
|
||||
'interactiveplot':script,
|
||||
'the_div':div,
|
||||
'mapscript':mapscript,
|
||||
@@ -16464,10 +16513,31 @@ def virtualevent_addboat_view(request,id=0):
|
||||
]
|
||||
|
||||
|
||||
buttons = []
|
||||
|
||||
if not request.user.is_anonymous():
|
||||
if race_can_register(r,race):
|
||||
buttons += ['registerbutton']
|
||||
|
||||
if race_can_adddiscipline(r,race):
|
||||
buttons += ['adddisciplinebutton']
|
||||
|
||||
if race_can_submit(r,race):
|
||||
buttons += ['submitbutton']
|
||||
|
||||
if race_can_resubmit(r,race):
|
||||
buttons += ['resubmitbutton']
|
||||
|
||||
if race_can_withdraw(r,race):
|
||||
buttons += ['withdrawbutton']
|
||||
|
||||
if race_can_edit(r,race):
|
||||
buttons += ['editbutton']
|
||||
|
||||
return render(request,'virtualeventregister.html',
|
||||
{
|
||||
'form':form,
|
||||
'buttons':buttons,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'race':race,
|
||||
'userid':r.user.id,
|
||||
@@ -16593,9 +16663,32 @@ def virtualevent_register_view(request,id=0):
|
||||
'name': 'Register'
|
||||
}
|
||||
]
|
||||
|
||||
buttons = []
|
||||
|
||||
if not request.user.is_anonymous():
|
||||
if race_can_register(r,race):
|
||||
buttons += ['registerbutton']
|
||||
|
||||
if race_can_adddiscipline(r,race):
|
||||
buttons += ['adddisciplinebutton']
|
||||
|
||||
if race_can_submit(r,race):
|
||||
buttons += ['submitbutton']
|
||||
|
||||
if race_can_resubmit(r,race):
|
||||
buttons += ['resubmitbutton']
|
||||
|
||||
if race_can_withdraw(r,race):
|
||||
buttons += ['withdrawbutton']
|
||||
|
||||
if race_can_edit(r,race):
|
||||
buttons += ['editbutton']
|
||||
|
||||
return render(request,'virtualeventregister.html',
|
||||
{
|
||||
'form':form,
|
||||
'buttons':buttons,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'race':race,
|
||||
'userid':r.user.id,
|
||||
@@ -16717,9 +16810,31 @@ def indoorvirtualevent_register_view(request,id=0):
|
||||
}
|
||||
]
|
||||
|
||||
buttons = []
|
||||
|
||||
if not request.user.is_anonymous():
|
||||
if race_can_register(r,race):
|
||||
buttons += ['registerbutton']
|
||||
|
||||
if race_can_adddiscipline(r,race):
|
||||
buttons += ['adddisciplinebutton']
|
||||
|
||||
if race_can_submit(r,race):
|
||||
buttons += ['submitbutton']
|
||||
|
||||
if race_can_resubmit(r,race):
|
||||
buttons += ['resubmitbutton']
|
||||
|
||||
if race_can_withdraw(r,race):
|
||||
buttons += ['withdrawbutton']
|
||||
|
||||
if race_can_edit(r,race):
|
||||
buttons += ['editbutton']
|
||||
|
||||
return render(request,'virtualeventregister.html',
|
||||
{
|
||||
'form':form,
|
||||
'buttons':buttons,
|
||||
'race':race,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'userid':r.user.id,
|
||||
@@ -17067,10 +17182,32 @@ def virtualevent_edit_view(request,id=0):
|
||||
}
|
||||
]
|
||||
|
||||
buttons = []
|
||||
|
||||
if not request.user.is_anonymous():
|
||||
if race_can_register(r,race):
|
||||
buttons += ['registerbutton']
|
||||
|
||||
if race_can_adddiscipline(r,race):
|
||||
buttons += ['adddisciplinebutton']
|
||||
|
||||
if race_can_submit(r,race):
|
||||
buttons += ['submitbutton']
|
||||
|
||||
if race_can_resubmit(r,race):
|
||||
buttons += ['resubmitbutton']
|
||||
|
||||
if race_can_withdraw(r,race):
|
||||
buttons += ['withdrawbutton']
|
||||
|
||||
if race_can_edit(r,race):
|
||||
buttons += ['editbutton']
|
||||
|
||||
return render(request,'virtualeventedit.html',
|
||||
{
|
||||
'form':racecreateform,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'buttons':buttons,
|
||||
'rower':r,
|
||||
'race':race,
|
||||
|
||||
@@ -17143,9 +17280,33 @@ def indoorvirtualevent_edit_view(request,id=0):
|
||||
'name': 'Edit'
|
||||
}
|
||||
]
|
||||
|
||||
buttons = []
|
||||
|
||||
if not request.user.is_anonymous():
|
||||
if race_can_register(r,race):
|
||||
buttons += ['registerbutton']
|
||||
|
||||
if race_can_adddiscipline(r,race):
|
||||
buttons += ['adddisciplinebutton']
|
||||
|
||||
if race_can_submit(r,race):
|
||||
buttons += ['submitbutton']
|
||||
|
||||
if race_can_resubmit(r,race):
|
||||
buttons += ['resubmitbutton']
|
||||
|
||||
if race_can_withdraw(r,race):
|
||||
buttons += ['withdrawbutton']
|
||||
|
||||
if race_can_edit(r,race):
|
||||
buttons += ['editbutton']
|
||||
|
||||
|
||||
return render(request,'virtualeventedit.html',
|
||||
{
|
||||
'form':racecreateform,
|
||||
'buttons':buttons,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'rower':r,
|
||||
'race':race,
|
||||
|
||||
Reference in New Issue
Block a user