form initial now has better default initial
This commit is contained in:
@@ -418,7 +418,17 @@ class UploadOptionsForm(forms.Form):
|
|||||||
choices2 = [(r.id,str(r)) for r in registrations2]
|
choices2 = [(r.id,str(r)) for r in registrations2]
|
||||||
choices3 = [(0,'---')]
|
choices3 = [(0,'---')]
|
||||||
|
|
||||||
choices = choices3+choices1+choices2
|
noregistrations = []
|
||||||
|
for ra in VirtualRace.objects.filter(registration_closure__gt=timezone.now(),sessiontype='race'):
|
||||||
|
rs = VirtualRaceResult.objects.filter(race = ra,userid=r.id)
|
||||||
|
if rs.count()==0:
|
||||||
|
noregistrations.append((-ra.id,ra.name))
|
||||||
|
for ra in VirtualRace.objects.filter(registration_closure__gt=timezone.now(),sessiontype='indoorrace'):
|
||||||
|
rs = IndoorVirtualRaceResult.objects.filter(race = ra,userid=r.id)
|
||||||
|
if rs.count()==0:
|
||||||
|
noregistrations.append((-ra.id,ra.name))
|
||||||
|
|
||||||
|
choices = choices3+choices1+choices2+noregistrations
|
||||||
|
|
||||||
if int(raceid) in [r.id for r in races]:
|
if int(raceid) in [r.id for r in races]:
|
||||||
therace = VirtualRace.objects.get(id=raceid)
|
therace = VirtualRace.objects.get(id=raceid)
|
||||||
|
|||||||
@@ -2648,7 +2648,7 @@ class VirtualRaceForm(ModelForm):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
registration_closure = enddatetime+datetime.timedelta(days=1)
|
registration_closure = enddatetime+datetime.timedelta(days=1)
|
||||||
cd['registration_closure'] = registration_closure
|
cd['registration_closure'] = registration_closure
|
||||||
|
|
||||||
registration_form = cd['registration_form']
|
registration_form = cd['registration_form']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -3124,6 +3124,8 @@ class CourseTestResult(models.Model):
|
|||||||
distance = models.IntegerField(default=0)
|
distance = models.IntegerField(default=0)
|
||||||
coursecompleted = models.BooleanField(default=False)
|
coursecompleted = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IndoorVirtualRaceResultForm(ModelForm):
|
class IndoorVirtualRaceResultForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = IndoorVirtualRaceResult
|
model = IndoorVirtualRaceResult
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ from rowers.models import (
|
|||||||
GeoCourse, TrainingMicroCycle,TrainingMesoCycle,TrainingMacroCycle,
|
GeoCourse, TrainingMicroCycle,TrainingMesoCycle,TrainingMacroCycle,
|
||||||
TrainingPlan,PlannedSession,VirtualRaceResult,CourseTestResult,
|
TrainingPlan,PlannedSession,VirtualRaceResult,CourseTestResult,
|
||||||
get_course_timezone, IndoorVirtualRaceResult,VirtualRace,createmacrofillers,
|
get_course_timezone, IndoorVirtualRaceResult,VirtualRace,createmacrofillers,
|
||||||
createmesofillers,createmicrofillers,
|
createmesofillers,createmicrofillers,CourseStandard,
|
||||||
)
|
)
|
||||||
|
|
||||||
from rowers.courses import get_time_course
|
from rowers.courses import get_time_course
|
||||||
@@ -1341,9 +1341,70 @@ def remove_rower_race(r,race,recordid=None):
|
|||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
def default_class(r,w,race):
|
||||||
|
if r.birthdate:
|
||||||
|
age = calculate_age(r.birthdate)
|
||||||
|
else:
|
||||||
|
age = 25
|
||||||
|
|
||||||
|
sex = r.sex
|
||||||
|
if sex=='not specified':
|
||||||
|
sex='male'
|
||||||
|
|
||||||
|
if w is not None:
|
||||||
|
boatclass = w.workouttype
|
||||||
|
boattype = w.boattype
|
||||||
|
|
||||||
|
adaptiveclass = w.adaptiveclass
|
||||||
|
weightclass = w.weightcategory
|
||||||
|
else:
|
||||||
|
if race.sessiontype == 'race':
|
||||||
|
boatclass = 'water'
|
||||||
|
else:
|
||||||
|
boatclass = 'rower'
|
||||||
|
boattype = '1x'
|
||||||
|
adaptiveclass = 'None'
|
||||||
|
weightclass = 'hwt'
|
||||||
|
|
||||||
|
if race.coursestandards:
|
||||||
|
standards = CourseStandard.objects.filter(
|
||||||
|
agemin__lt=age,agemax__gt=age,
|
||||||
|
boatclass=boatclass,
|
||||||
|
adaptiveclass=adaptiveclass,
|
||||||
|
boattype=boattype,
|
||||||
|
weightclass=weightclass
|
||||||
|
).order_by("agemax","-agemin","boattype")
|
||||||
|
|
||||||
|
|
||||||
|
if standards.count()==0:
|
||||||
|
# omit weight
|
||||||
|
standards = CourseStandard.objects.filter(agemin__lt=age,agemax__gt=age,
|
||||||
|
boatclass=boatclass,
|
||||||
|
adaptiveclass=adaptiveclass,
|
||||||
|
boattype=boattype,
|
||||||
|
)
|
||||||
|
if standards.count()==0:
|
||||||
|
standards = CourseStandard.objects.filter(agemin__lt=age,agemax__gt=age,
|
||||||
|
boattype=boattype)
|
||||||
|
if standards.count()==0:
|
||||||
|
standards = CourseStandard.objects.filter(agemin__lt=age,agemax__gt=age)
|
||||||
|
|
||||||
|
if standards.count()==0:
|
||||||
|
# boolean, boattype, boatclass, adaptiveclass, weightclass, sex, coursestandard,
|
||||||
|
return False,'1x','water',None,'hwt','male',None
|
||||||
|
|
||||||
|
if standards.count()>0:
|
||||||
|
# find optimum standard
|
||||||
|
s = standards[0]
|
||||||
|
return True,s.boattype,s.boatclass,s.adaptiveclass,s.weightclass,s.sex,s
|
||||||
|
|
||||||
|
# No Course Standard
|
||||||
|
return True,boattype,boatclass,adaptiveclass,weightclass,sex,None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Low Level functions - to be called by higher level methods
|
# Low Level functions - to be called by higher level methods
|
||||||
def add_workout_indoorrace(ws,race,r,recordid=0):
|
def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
|
||||||
print('aap')
|
|
||||||
result = 0
|
result = 0
|
||||||
comments = []
|
comments = []
|
||||||
errors = []
|
errors = []
|
||||||
@@ -1403,11 +1464,14 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
|
|||||||
workoutid = ws[0].id
|
workoutid = ws[0].id
|
||||||
)
|
)
|
||||||
|
|
||||||
print(record,records)
|
|
||||||
|
|
||||||
if not record:
|
|
||||||
|
if not record and not doregister:
|
||||||
errors.append("Couldn't find this entry")
|
errors.append("Couldn't find this entry")
|
||||||
return result,comments,errors,0
|
return result,comments,errors,0
|
||||||
|
elif not record:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if race.sessionmode == 'distance':
|
if race.sessionmode == 'distance':
|
||||||
if ws[0].distance != race.sessionvalue:
|
if ws[0].distance != race.sessionvalue:
|
||||||
@@ -1532,7 +1596,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
|
|||||||
workoutid = ws[0].id
|
workoutid = ws[0].id
|
||||||
)
|
)
|
||||||
|
|
||||||
if not record:
|
if not record and not doregister:
|
||||||
errors.append("Couldn't find this entry")
|
errors.append("Couldn't find this entry")
|
||||||
return result,comments,errors,0
|
return result,comments,errors,0
|
||||||
|
|
||||||
|
|||||||
@@ -1499,6 +1499,7 @@ def virtualevent_addboat_view(request,id=0):
|
|||||||
raise Http404("Virtual Challenge does not exist")
|
raise Http404("Virtual Challenge does not exist")
|
||||||
|
|
||||||
categories = None
|
categories = None
|
||||||
|
hasinitial,boattype,boatclass,adaptiveclass,weightclass,sex,initialcategory = default_class(r,None,race)
|
||||||
if race.coursestandards is not None:
|
if race.coursestandards is not None:
|
||||||
categories = CourseStandard.objects.filter(
|
categories = CourseStandard.objects.filter(
|
||||||
standardcollection=race.coursestandards).order_by("name")
|
standardcollection=race.coursestandards).order_by("name")
|
||||||
@@ -1700,11 +1701,22 @@ def virtualevent_addboat_view(request,id=0):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
initial = {
|
if hasinitial:
|
||||||
'age': calculate_age(r.birthdate),
|
initial = {
|
||||||
'weightcategory': r.weightcategory,
|
'age': calculate_age(r.birthdate),
|
||||||
'adaptiveclass': r.adaptiveclass,
|
'boattype':boattype,
|
||||||
|
'boatclass':boatclass,
|
||||||
|
'adaptiveclass':adaptiveclass,
|
||||||
|
'weightclass':weightclass,
|
||||||
|
'sex':sex,
|
||||||
|
'entrycategory':initialcategory,
|
||||||
}
|
}
|
||||||
|
else:
|
||||||
|
initial = {
|
||||||
|
'age': calculate_age(r.birthdate),
|
||||||
|
'weightcategory': r.weightcategory,
|
||||||
|
'adaptiveclass': r.adaptiveclass,
|
||||||
|
}
|
||||||
|
|
||||||
categories = None
|
categories = None
|
||||||
if race.coursestandards is not None:
|
if race.coursestandards is not None:
|
||||||
@@ -1774,6 +1786,7 @@ def virtualevent_register_view(request,id=0):
|
|||||||
raise Http404("Virtual Challenge does not exist")
|
raise Http404("Virtual Challenge does not exist")
|
||||||
|
|
||||||
categories = None
|
categories = None
|
||||||
|
hasinitial,boattype,boatclass,adaptiveclass,weightclass,sex,initialcategory = default_class(r,None,race)
|
||||||
if race.coursestandards is not None:
|
if race.coursestandards is not None:
|
||||||
categories = CourseStandard.objects.filter(
|
categories = CourseStandard.objects.filter(
|
||||||
standardcollection=race.coursestandards).order_by("name")
|
standardcollection=race.coursestandards).order_by("name")
|
||||||
@@ -1937,11 +1950,22 @@ def virtualevent_register_view(request,id=0):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
initial = {
|
if hasinitial:
|
||||||
'age': calculate_age(r.birthdate),
|
initial = {
|
||||||
'weightcategory': r.weightcategory,
|
'age': calculate_age(r.birthdate),
|
||||||
'adaptiveclass': r.adaptiveclass,
|
'boattype':boattype,
|
||||||
|
'boatclass':boatclass,
|
||||||
|
'adaptiveclass':adaptiveclass,
|
||||||
|
'weightclass':weightclass,
|
||||||
|
'sex':sex,
|
||||||
|
'entrycategory':initialcategory,
|
||||||
}
|
}
|
||||||
|
else:
|
||||||
|
initial = {
|
||||||
|
'age': calculate_age(r.birthdate),
|
||||||
|
'weightcategory': r.weightcategory,
|
||||||
|
'adaptiveclass': r.adaptiveclass,
|
||||||
|
}
|
||||||
|
|
||||||
categories = None
|
categories = None
|
||||||
if race.coursestandards is not None:
|
if race.coursestandards is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user