register multiple disciplines
This commit is contained in:
@@ -699,17 +699,17 @@ class WorkoutSessionSelectForm(forms.Form):
|
||||
)
|
||||
|
||||
class WorkoutRaceSelectForm(forms.Form):
|
||||
evaluate_after = forms.TimeField(
|
||||
input_formats=['%H:%M:%S.%f',
|
||||
'%H:%M:%S',
|
||||
'%H:%M:%S',
|
||||
'%M:%S.%f',
|
||||
'%M:%S',
|
||||
'%M'],
|
||||
label = 'Only Evaluate After:',
|
||||
required=False)
|
||||
# evaluate_after = forms.TimeField(
|
||||
# input_formats=['%H:%M:%S.%f',
|
||||
# '%H:%M:%S',
|
||||
# '%H:%M:%S',
|
||||
# '%M:%S.%f',
|
||||
# '%M:%S',
|
||||
# '%M'],
|
||||
# label = 'Only Evaluate After:',
|
||||
# required=False)
|
||||
|
||||
def __init__(self, workoutdata, *args, **kwargs):
|
||||
def __init__(self, workoutdata,entries, *args, **kwargs):
|
||||
|
||||
super(WorkoutRaceSelectForm, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -720,6 +720,12 @@ class WorkoutRaceSelectForm(forms.Form):
|
||||
widget=forms.RadioSelect,
|
||||
)
|
||||
|
||||
self.fields['record'] = forms.ChoiceField(
|
||||
label = 'Entry',
|
||||
choices = entries['choices'],
|
||||
initial = entries['initial'],
|
||||
)
|
||||
|
||||
# self.fields['evaluate_after'] =
|
||||
|
||||
class PlannedSessionTeamForm(forms.Form):
|
||||
|
||||
@@ -1587,6 +1587,19 @@ class VirtualRaceResult(models.Model):
|
||||
|
||||
age = models.IntegerField(null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
rr = Rower.objects.get(id=self.userid)
|
||||
name = '{u1} {u2}'.format(
|
||||
u1 = rr.user.first_name,
|
||||
u2 = rr.user.last_name,
|
||||
)
|
||||
return u'Entry for {n} for "{r}" in {d}'.format(
|
||||
n = name,
|
||||
r = self.race,
|
||||
d = self.boattype,
|
||||
)
|
||||
|
||||
|
||||
class CourseTestResult(models.Model):
|
||||
userid = models.IntegerField(default=0)
|
||||
workoutid = models.IntegerField(null=True)
|
||||
@@ -1600,6 +1613,13 @@ class VirtualRaceResultForm(ModelForm):
|
||||
model = VirtualRaceResult
|
||||
fields = ['teamname','weightcategory','boattype','age']
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
boattypes = kwargs.pop('boattypes',None)
|
||||
super(VirtualRaceResultForm, self).__init__(*args, **kwargs)
|
||||
|
||||
if boattypes:
|
||||
self.fields['boattype'].choices = boattypes
|
||||
|
||||
from rowers.metrics import rowingmetrics
|
||||
|
||||
|
||||
@@ -651,6 +651,32 @@ def race_can_resubmit(r,race):
|
||||
|
||||
return False
|
||||
|
||||
def race_can_adddiscipline(r,race):
|
||||
if r not in race.rower.all():
|
||||
return False
|
||||
|
||||
start_time = race.start_time
|
||||
start_date = race.startdate
|
||||
startdatetime = datetime.combine(start_date,start_time)
|
||||
startdatetime = pytz.timezone(race.timezone).localize(
|
||||
startdatetime
|
||||
)
|
||||
evaluation_closure = race.evaluation_closure
|
||||
|
||||
|
||||
|
||||
if timezone.now() < evaluation_closure:
|
||||
is_complete,has_registered = race_rower_status(r,race)
|
||||
if has_registered:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def race_can_withdraw(r,race):
|
||||
if r not in race.rower.all():
|
||||
return False
|
||||
@@ -699,20 +725,25 @@ def add_rower_race(r,race):
|
||||
|
||||
return 1
|
||||
|
||||
def remove_rower_race(r,race):
|
||||
def remove_rower_race(r,race,recordid=None):
|
||||
race.rower.remove(r)
|
||||
|
||||
records = VirtualRaceResult.objects.filter(userid=r.id,
|
||||
workoutid__isnull=True,
|
||||
race=race)
|
||||
|
||||
if recordid:
|
||||
records = VirtualRaceResult.objects.filter(userid=r.id,
|
||||
workoutid__isnull=True,
|
||||
race=race,
|
||||
id=recordid)
|
||||
else:
|
||||
records = VirtualRaceResult.objects.filter(userid=r.id,
|
||||
workoutid__isnull=True,
|
||||
race=race,)
|
||||
for r in records:
|
||||
r.delete()
|
||||
|
||||
return 1
|
||||
|
||||
# Low Level functions - to be called by higher level methods
|
||||
def add_workout_race(ws,race,r,splitsecond=0):
|
||||
def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
|
||||
result = 0
|
||||
comments = []
|
||||
errors = []
|
||||
@@ -758,12 +789,21 @@ def add_workout_race(ws,race,r,splitsecond=0):
|
||||
else:
|
||||
age = None
|
||||
|
||||
record = VirtualRaceResult.objects.get(
|
||||
userid=r.id,
|
||||
race=race,
|
||||
id=recordid
|
||||
)
|
||||
|
||||
records = VirtualRaceResult.objects.filter(
|
||||
userid=r.id,
|
||||
race=race
|
||||
)
|
||||
|
||||
record = records[0]
|
||||
race=race,
|
||||
workoutid = ws[0].id
|
||||
)
|
||||
|
||||
if not record:
|
||||
errors.append("Couldn't find this entry")
|
||||
return result,comments,errors,0
|
||||
|
||||
if ws[0].boattype != record.boattype:
|
||||
errors.append('Your workout boat type did not match the boat type you registered')
|
||||
@@ -774,18 +814,22 @@ def add_workout_race(ws,race,r,splitsecond=0):
|
||||
return 0,comments, errors,0
|
||||
|
||||
# start adding sessions
|
||||
for w in ws:
|
||||
if w.startdatetime>=startdatetime and w.startdatetime<=enddatetime:
|
||||
w.plannedsession = race
|
||||
w.save()
|
||||
result += 1
|
||||
if ws[0].startdatetime>=startdatetime and ws[0].startdatetime<=enddatetime:
|
||||
ws[0].plannedsession = race
|
||||
ws[0].save()
|
||||
result += 1
|
||||
|
||||
else:
|
||||
errors.append('Workout %i did not match the race window' % w.id)
|
||||
return result,comments,errors,0
|
||||
else:
|
||||
errors.append('Workout %i did not match the race window' % ws[0].id)
|
||||
return result,comments,errors,0
|
||||
|
||||
if result>0:
|
||||
|
||||
for otherrecord in records:
|
||||
print otherrecord
|
||||
otherrecord.workoutid = None
|
||||
otherrecord.coursecompleted = False
|
||||
otherrecord.save()
|
||||
|
||||
job = myqueue(queue,handle_check_race_course,ws[0].csvfilename,
|
||||
ws[0].id,race.course.id,record.id,splitsecond=splitsecond)
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
<form id="race_submit_form"
|
||||
method="post">
|
||||
<div class="grid_12 alpha">
|
||||
<div class="grid_6 alpha">
|
||||
<p>Select one of the following workouts that you rowed within the race window</p>
|
||||
<table width="100%">
|
||||
<tr>
|
||||
@@ -42,24 +41,6 @@
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="grid_6 omega">
|
||||
<p>The "Only Evaluate After" field allows you to tell the site to
|
||||
discard the first N minutes fo the workout. This is useful if you
|
||||
paddled through the start polygon as part of your warming up.
|
||||
Fill out the
|
||||
time at which you want to start the evaluation, or leave empty to
|
||||
evaluate the entire workout. </p>
|
||||
<p>Use any of the following formats:
|
||||
<ul>
|
||||
<li>H:MM:SS.d, e.g. 1:45:00.0 for one hour and 45 minutes</li>
|
||||
<li>H:MM:SS, e.g. 1:45:00 for one hour and 45 minutes</li>
|
||||
<li>MM:SS.d, e.g. 30:00.0 for thirty minutes</li>
|
||||
<li>MM, e.g. 30 for thirty minutes</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid_2 prefix_2 suffix_8">
|
||||
{% csrf_token %}
|
||||
|
||||
@@ -83,6 +83,9 @@
|
||||
{% if button == 'withdrawbutton' %}
|
||||
<a href="/rowers/virtualevent/{{ race.id }}/withdraw" class="button gray small grid_2">Withdraw</a>
|
||||
{% endif %}
|
||||
{% if button == 'adddisciplinebutton' %}
|
||||
<a href="/rowers/virtualevent/{{ race.id }}/adddiscipline" class="button gray small grid_2">Register New Boat</a>
|
||||
{% endif %}
|
||||
{% if button == 'editbutton' %}
|
||||
<a href="/rowers/virtualevent/{{ race.id }}/edit" class="button gray small grid_2">Edit Race</a>
|
||||
{% endif %}
|
||||
@@ -167,6 +170,11 @@
|
||||
<td>{{ record.boattype }}</td>
|
||||
<td>{{ record.age }}</td>
|
||||
<td>{{ record.weightcategory }}</td>
|
||||
{% if record.userid == rower.id %}
|
||||
<td>
|
||||
<a href="/rowers/virtualevent/{{ race.id }}/withdraw/{{ record.id }}" >Withdraw</a>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
@@ -149,6 +149,8 @@ urlpatterns = [
|
||||
url(r'^virtualevent/(?P<id>\d+)$',views.virtualevent_view),
|
||||
url(r'^virtualevent/(?P<id>\d+)/edit$',views.virtualevent_edit_view),
|
||||
url(r'^virtualevent/(?P<id>\d+)/register$',views.virtualevent_register_view),
|
||||
url(r'^virtualevent/(?P<id>\d+)/adddiscipline$',views.virtualevent_addboat_view),
|
||||
url(r'^virtualevent/(?P<id>\d+)/withdraw/(?P<recordid>\d+)$',views.virtualevent_withdraw_view),
|
||||
url(r'^virtualevent/(?P<id>\d+)/withdraw$',views.virtualevent_withdraw_view),
|
||||
url(r'^virtualevent/(?P<id>\d+)/submit$',
|
||||
views.virtualevent_submit_result_view),
|
||||
|
||||
154
rowers/views.py
154
rowers/views.py
@@ -13440,6 +13440,9 @@ def virtualevent_view(request,id=0):
|
||||
if race_can_register(r,race):
|
||||
buttons += ['registerbutton']
|
||||
|
||||
if race_can_adddiscipline(r,race):
|
||||
buttons += ['adddisciplinebutton']
|
||||
|
||||
if race_can_submit(r,race):
|
||||
buttons += ['submitbutton']
|
||||
|
||||
@@ -13485,7 +13488,7 @@ def virtualevent_view(request,id=0):
|
||||
})
|
||||
|
||||
@login_required()
|
||||
def virtualevent_withdraw_view(request,id=0):
|
||||
def virtualevent_withdraw_view(request,id=0,recordid=None):
|
||||
r = getrower(request.user)
|
||||
try:
|
||||
race = VirtualRace.objects.get(id=id)
|
||||
@@ -13493,7 +13496,7 @@ def virtualevent_withdraw_view(request,id=0):
|
||||
raise Http404("Virtual Race does not exist")
|
||||
|
||||
if race_can_withdraw(r,race):
|
||||
remove_rower_race(r,race)
|
||||
remove_rower_race(r,race,recordid=recordid)
|
||||
messages.info(request,
|
||||
"You have successfully withdrawn from this race.")
|
||||
else:
|
||||
@@ -13506,6 +13509,106 @@ def virtualevent_withdraw_view(request,id=0):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
@login_required()
|
||||
def virtualevent_addboat_view(request,id=0):
|
||||
r = getrower(request.user)
|
||||
try:
|
||||
race = VirtualRace.objects.get(id=id)
|
||||
except VirtualRace.DoesNotExist:
|
||||
raise Http404("Virtual Race does not exist")
|
||||
|
||||
if not race_can_adddiscipline(r,race):
|
||||
messages.error(request,"You cannot register for this race")
|
||||
|
||||
url = reverse(virtualevent_view,
|
||||
kwargs = {
|
||||
'id':race.id
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
records = VirtualRaceResult.objects.filter(
|
||||
userid = r.id,
|
||||
race = race
|
||||
)
|
||||
|
||||
boattypes = [record.boattype for record in records]
|
||||
allowedboats = tuple([ type for type in types.boattypes if type[0] not in boattypes] )
|
||||
|
||||
|
||||
# we're still here
|
||||
if request.method == 'POST':
|
||||
# process form
|
||||
form = VirtualRaceResultForm(request.POST)
|
||||
if form.is_valid():
|
||||
cd = form.cleaned_data
|
||||
teamname = cd['teamname']
|
||||
boattype = cd['boattype']
|
||||
weightcategory = cd['weightcategory']
|
||||
age = cd['age']
|
||||
if boattype == '1x' and r.birthdate:
|
||||
age = calculate_age(r.birthdate)
|
||||
|
||||
if boattype in boattypes:
|
||||
messages.error(request,"You have already registered in that boat type")
|
||||
url = reverse(virtualevent_view,
|
||||
kwargs = {
|
||||
'id': race.id
|
||||
}
|
||||
)
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
record = VirtualRaceResult(
|
||||
userid=r.id,
|
||||
teamname=teamname,
|
||||
race=race,
|
||||
username = u'{f} {l}'.format(
|
||||
f = r.user.first_name,
|
||||
l = r.user.last_name
|
||||
),
|
||||
weightcategory=weightcategory,
|
||||
duration=datetime.time(0,0),
|
||||
boattype=boattype,
|
||||
coursecompleted=False,
|
||||
sex=r.sex,
|
||||
age=age
|
||||
)
|
||||
|
||||
record.save()
|
||||
|
||||
add_rower_race(r,race)
|
||||
|
||||
|
||||
|
||||
messages.info(
|
||||
request,
|
||||
"You have successfully registered for this race. Good luck!"
|
||||
)
|
||||
|
||||
url = reverse(virtualevent_view,
|
||||
kwargs = {
|
||||
'id':race.id
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
else:
|
||||
initial = {
|
||||
'age': calculate_age(r.birthdate),
|
||||
'weightcategory': r.weightcategory,
|
||||
}
|
||||
|
||||
form = VirtualRaceResultForm(initial=initial,boattypes=allowedboats)
|
||||
|
||||
return render(request,'virtualeventregister.html',
|
||||
{
|
||||
'form':form,
|
||||
'race':race,
|
||||
'rowerid':r.id,
|
||||
|
||||
})
|
||||
|
||||
@login_required()
|
||||
def virtualevent_register_view(request,id=0):
|
||||
r = getrower(request.user)
|
||||
@@ -13787,6 +13890,21 @@ def virtualevent_submit_result_view(request,id=0):
|
||||
|
||||
can_submit = race_can_submit(r,race) or race_can_resubmit(r,race)
|
||||
|
||||
records = VirtualRaceResult.objects.filter(
|
||||
userid = r.id,
|
||||
race=race
|
||||
)
|
||||
|
||||
entrychoices = []
|
||||
|
||||
for record in records:
|
||||
rtpl = (record.id, record.__unicode__())
|
||||
entrychoices.append(rtpl)
|
||||
|
||||
entries = {}
|
||||
entries['choices'] = entrychoices
|
||||
entries['initial'] = [records[0].id]
|
||||
|
||||
if not can_submit:
|
||||
messages.error(request,'You cannot submit a result to this race')
|
||||
url = reverse(virtualevent_view,
|
||||
@@ -13820,18 +13938,20 @@ def virtualevent_submit_result_view(request,id=0):
|
||||
workoutdata['choices'] = tuple(choices)
|
||||
|
||||
if request.method == 'POST':
|
||||
w_form = WorkoutRaceSelectForm(workoutdata,request.POST)
|
||||
w_form = WorkoutRaceSelectForm(workoutdata,entries,request.POST)
|
||||
|
||||
if w_form.is_valid():
|
||||
selectedworkout = w_form.cleaned_data['workouts']
|
||||
splittime = w_form.cleaned_data['evaluate_after']
|
||||
if splittime is not None:
|
||||
splitsecond = splittime.hour*3600
|
||||
splitsecond += splittime.minute*60
|
||||
splitsecond += splittime.second
|
||||
splitsecond += splittime.microsecond/1.e6
|
||||
else:
|
||||
splitsecond = 0
|
||||
splitsecond = 0
|
||||
recordid = w_form.cleaned_data['record']
|
||||
# splittime = w_form.cleaned_data['evaluate_after']
|
||||
# if splittime is not None:
|
||||
# splitsecond = splittime.hour*3600
|
||||
# splitsecond += splittime.minute*60
|
||||
# splitsecond += splittime.second
|
||||
# splitsecond += splittime.microsecond/1.e6
|
||||
# else:
|
||||
# splitsecond = 0
|
||||
else:
|
||||
selectedworkout = None
|
||||
|
||||
@@ -13843,11 +13963,11 @@ def virtualevent_submit_result_view(request,id=0):
|
||||
|
||||
result,comments,errors,jobid = add_workout_race(
|
||||
workouts,race,r,
|
||||
splitsecond=splitsecond)
|
||||
if result:
|
||||
for w in ws:
|
||||
remove_workout_plannedsession(w,race)
|
||||
delete_race_result(w,race)
|
||||
splitsecond=splitsecond,recordid=recordid)
|
||||
# if result:
|
||||
# for w in ws:
|
||||
# remove_workout_plannedsession(w,race)
|
||||
# delete_race_result(w,race)
|
||||
|
||||
for c in comments:
|
||||
messages.info(request,c)
|
||||
@@ -13871,7 +13991,7 @@ def virtualevent_submit_result_view(request,id=0):
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
else:
|
||||
w_form = WorkoutRaceSelectForm(workoutdata=workoutdata)
|
||||
w_form = WorkoutRaceSelectForm(workoutdata,entries)
|
||||
|
||||
return render(request,'race_submit.html',
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user