adding race selector to workout upload
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.admin.widgets import FilteredSelectMultiple
|
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 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.forms import UserCreationForm
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
@@ -16,6 +19,7 @@ from utils import landingpages
|
|||||||
from metrics import axes
|
from metrics import axes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# login form
|
# login form
|
||||||
class LoginForm(forms.Form):
|
class LoginForm(forms.Form):
|
||||||
username = forms.CharField()
|
username = forms.CharField()
|
||||||
@@ -254,6 +258,10 @@ class UploadOptionsForm(forms.Form):
|
|||||||
makeprivate = forms.BooleanField(initial=False,required=False,
|
makeprivate = forms.BooleanField(initial=False,required=False,
|
||||||
label='Make Workout Private')
|
label='Make Workout Private')
|
||||||
|
|
||||||
|
submitrace = forms.ModelChoiceField(queryset=VirtualRace.objects.all(),
|
||||||
|
label='Submit as Race Result',
|
||||||
|
required=False)
|
||||||
|
|
||||||
landingpage = forms.ChoiceField(choices=nextpages,
|
landingpage = forms.ChoiceField(choices=nextpages,
|
||||||
initial='workout_edit_view',
|
initial='workout_edit_view',
|
||||||
label='After Upload, go to')
|
label='After Upload, go to')
|
||||||
@@ -261,6 +269,28 @@ class UploadOptionsForm(forms.Form):
|
|||||||
class Meta:
|
class Meta:
|
||||||
fields = ['make_plot','plottype','upload_toc2','makeprivate']
|
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
|
# The form to indicate additional actions to be performed immediately
|
||||||
# after a successful upload. This version allows the Team manager to select
|
# after a successful upload. This version allows the Team manager to select
|
||||||
# a team member
|
# a team member
|
||||||
|
|||||||
@@ -1006,6 +1006,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
|
|||||||
record.duration = ws[0].duration
|
record.duration = ws[0].duration
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ws[0].weightcategory != record.weightcategory:
|
if ws[0].weightcategory != record.weightcategory:
|
||||||
errors.append('Your workout weight category did not match the weight category you registered')
|
errors.append('Your workout weight category did not match the weight category you registered')
|
||||||
return 0,comments, errors,0
|
return 0,comments, errors,0
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
<i class="fas fa-file-plus fa-fw"></i> Submit Workout</a>
|
<i class="fas fa-file-plus fa-fw"></i> Submit Workout</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="/rowers/upload">
|
<a href="/rowers/workout/upload">
|
||||||
<i class="fas fa-file-upload fa-fw"></i> Upload your race result
|
<i class="fas fa-file-upload fa-fw"></i> Upload your race result
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -37,10 +37,10 @@
|
|||||||
{% if rower %}
|
{% if rower %}
|
||||||
{% if race|can_register:rower %}
|
{% if race|can_register:rower %}
|
||||||
<a class="white dot" href="/rowers/virtualevent/{{ race.id }}"> </a>
|
<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 %}
|
{% elif race|race_complete:rower %}
|
||||||
<a class="green dot" href="/rowers/virtualevent/{{ race.id }}"> </a>
|
<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 %}
|
{% elif race|future_registered:rower %}
|
||||||
<a class="orange dot" href="/rowers/virtualevent/{{ race.id }}"> </a>
|
<a class="orange dot" href="/rowers/virtualevent/{{ race.id }}"> </a>
|
||||||
{% elif race|past_not_registered:rower %}
|
{% elif race|past_not_registered:rower %}
|
||||||
|
|||||||
165
rowers/views.py
165
rowers/views.py
@@ -11462,7 +11462,7 @@ def workout_upload_view(request,
|
|||||||
response = {}
|
response = {}
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = DocumentsForm(request.POST,request.FILES)
|
form = DocumentsForm(request.POST,request.FILES)
|
||||||
optionsform = UploadOptionsForm(request.POST)
|
optionsform = UploadOptionsForm(request.POST,request=request)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
# f = request.FILES['file']
|
# f = request.FILES['file']
|
||||||
@@ -11503,6 +11503,11 @@ def workout_upload_view(request,
|
|||||||
makeprivate = optionsform.cleaned_data['makeprivate']
|
makeprivate = optionsform.cleaned_data['makeprivate']
|
||||||
landingpage = optionsform.cleaned_data['landingpage']
|
landingpage = optionsform.cleaned_data['landingpage']
|
||||||
|
|
||||||
|
try:
|
||||||
|
race = optionsform.cleaned_data['submitrace']
|
||||||
|
except KeyError:
|
||||||
|
race = None
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'makeprivate':makeprivate,
|
'makeprivate':makeprivate,
|
||||||
'make_plot':make_plot,
|
'make_plot':make_plot,
|
||||||
@@ -11688,6 +11693,28 @@ def workout_upload_view(request,
|
|||||||
else:
|
else:
|
||||||
messages.error(request,message)
|
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':
|
if landingpage != 'workout_upload_view':
|
||||||
url = reverse(landingpage,
|
url = reverse(landingpage,
|
||||||
@@ -11736,7 +11763,8 @@ def workout_upload_view(request,
|
|||||||
uploadoptions['upload_to_MapMyFitness'] = True
|
uploadoptions['upload_to_MapMyFitness'] = True
|
||||||
|
|
||||||
form = DocumentsForm(initial=docformoptions)
|
form = DocumentsForm(initial=docformoptions)
|
||||||
optionsform = UploadOptionsForm(initial=uploadoptions)
|
optionsform = UploadOptionsForm(initial=uploadoptions,
|
||||||
|
request=request)
|
||||||
return render(request, 'document_form.html',
|
return render(request, 'document_form.html',
|
||||||
{'form':form,
|
{'form':form,
|
||||||
'active':'nav-workouts',
|
'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",
|
return render(request,"disqualification_view.html",
|
||||||
{'workout':workout,
|
{'workout':workout,
|
||||||
'active':'nav-racing',
|
'active':'nav-racing',
|
||||||
'graphs':g,
|
'graphs':g,
|
||||||
|
'buttons':buttons,
|
||||||
'interactiveplot':script,
|
'interactiveplot':script,
|
||||||
'the_div':div,
|
'the_div':div,
|
||||||
'mapscript':mapscript,
|
'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',
|
return render(request,'virtualeventregister.html',
|
||||||
{
|
{
|
||||||
'form':form,
|
'form':form,
|
||||||
|
'buttons':buttons,
|
||||||
'breadcrumbs':breadcrumbs,
|
'breadcrumbs':breadcrumbs,
|
||||||
'race':race,
|
'race':race,
|
||||||
'userid':r.user.id,
|
'userid':r.user.id,
|
||||||
@@ -16593,9 +16663,32 @@ def virtualevent_register_view(request,id=0):
|
|||||||
'name': 'Register'
|
'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',
|
return render(request,'virtualeventregister.html',
|
||||||
{
|
{
|
||||||
'form':form,
|
'form':form,
|
||||||
|
'buttons':buttons,
|
||||||
'breadcrumbs':breadcrumbs,
|
'breadcrumbs':breadcrumbs,
|
||||||
'race':race,
|
'race':race,
|
||||||
'userid':r.user.id,
|
'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',
|
return render(request,'virtualeventregister.html',
|
||||||
{
|
{
|
||||||
'form':form,
|
'form':form,
|
||||||
|
'buttons':buttons,
|
||||||
'race':race,
|
'race':race,
|
||||||
'breadcrumbs':breadcrumbs,
|
'breadcrumbs':breadcrumbs,
|
||||||
'userid':r.user.id,
|
'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',
|
return render(request,'virtualeventedit.html',
|
||||||
{
|
{
|
||||||
'form':racecreateform,
|
'form':racecreateform,
|
||||||
'breadcrumbs':breadcrumbs,
|
'breadcrumbs':breadcrumbs,
|
||||||
|
'buttons':buttons,
|
||||||
'rower':r,
|
'rower':r,
|
||||||
'race':race,
|
'race':race,
|
||||||
|
|
||||||
@@ -17143,9 +17280,33 @@ def indoorvirtualevent_edit_view(request,id=0):
|
|||||||
'name': 'Edit'
|
'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',
|
return render(request,'virtualeventedit.html',
|
||||||
{
|
{
|
||||||
'form':racecreateform,
|
'form':racecreateform,
|
||||||
|
'buttons':buttons,
|
||||||
'breadcrumbs':breadcrumbs,
|
'breadcrumbs':breadcrumbs,
|
||||||
'rower':r,
|
'rower':r,
|
||||||
'race':race,
|
'race':race,
|
||||||
|
|||||||
Reference in New Issue
Block a user