diff --git a/rowers/models.py b/rowers/models.py index 25a2ac34..53db424f 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -2206,7 +2206,7 @@ class CourseStandard(models.Model): name = models.CharField(max_length=150) coursedistance = models.IntegerField() coursetime = models.CharField(max_length=100,default="") - coursestandard = models.FloatField() # average boat speed + referencespeed = models.FloatField() # average boat speed agemin = models.IntegerField(default=0) agemax = models.IntegerField(default=120) boatclass = models.CharField(max_length=150) # corresponds to workout workouttype @@ -2966,7 +2966,7 @@ class VirtualRaceResult(models.Model): startsecond = models.FloatField(default=0) endsecond = models.FloatField(default=0) entrycategory = models.ForeignKey(CourseStandard,null=True,on_delete=models.SET_NULL, - verbose_name='Field') + verbose_name='Group') def __str__(self): rr = Rower.objects.get(id=self.userid) @@ -3012,6 +3012,7 @@ class IndoorVirtualRaceResult(models.Model): race = models.ForeignKey(VirtualRace,on_delete=models.CASCADE) duration = models.TimeField(default=datetime.time(1,0)) distance = models.IntegerField(default=0) + referencespeed = models.FloatField(default=5.0) points = models.IntegerField(default=0) boatclass = models.CharField(choices=boatclasses, max_length=40, @@ -3027,7 +3028,7 @@ class IndoorVirtualRaceResult(models.Model): emailnotifications = models.BooleanField(default=True, verbose_name = 'Receive challenge notifications by email') entrycategory = models.ForeignKey(CourseStandard,null=True,on_delete=models.SET_NULL, - verbose_name='Category') + verbose_name='Group') def __str__(self): rr = Rower.objects.get(id=self.userid) diff --git a/rowers/scoring.py b/rowers/scoring.py index 1156bc25..89de6745 100644 --- a/rowers/scoring.py +++ b/rowers/scoring.py @@ -41,7 +41,7 @@ def save_scoring(name,user,filename,id=0,notes=""): delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second,microseconds=t.microsecond) seconds = delta.total_seconds() - coursestandard = coursedistance/seconds + referencespeed = coursedistance/seconds except KeyError: continue @@ -88,7 +88,7 @@ def save_scoring(name,user,filename,id=0,notes=""): standard = CourseStandard( name=name, coursedistance=coursedistance, - coursestandard=coursestandard, + referencespeed=referencespeed, coursetime=coursetime, agemin=agemin, agemax=agemax, diff --git a/rowers/views/racesviews.py b/rowers/views/racesviews.py index db9aa416..5124e421 100644 --- a/rowers/views/racesviews.py +++ b/rowers/views/racesviews.py @@ -1631,6 +1631,40 @@ def virtualevent_register_view(request,id=0): if sex == 'not specified': sex = 'male' + + coursestandard = None + referencespeed = 5.0 + + if race.coursestandards is not None: + coursestandard = cd['entrycategory'] + referencespeed = coursestandard.referencespeed + boattype = coursestandard.boattype + boatclass = coursestandard.boatclass + weightcategory = coursestandard.weightcategory + adaptiveclass = coursestandard.adaptiveclass + skillclass = coursestandard.skillclass + + returnurl = reverse(virtualevent_register_view, + kwargs={'id':race.id}) + + if age < coursestandard.agemin: + messages.error(request,'You are younger than the minimum age for this group') + return HttpResponseRedirect(url) + + if age > coursestandard.agemax: + messages.error(request,'You are older than the maximum age for this group') + return HttpResponseRedirect(url) + + if sex == 'male' and coursestandard.sex != 'male': + messages.error(request,'Men are not allowed to enter this category') + return HttpResponseRedirect(url) + + if sex == 'mixed' and coursestandard.sex not in ['mixed','male']: + messages.error(request,'Mixed crews are not allowed to enter this category') + return HttpResponseRedirect(url) + + + record = VirtualRaceResult( userid=r.id, teamname=teamname, @@ -1646,7 +1680,8 @@ def virtualevent_register_view(request,id=0): boattype=boattype, coursecompleted=False, sex=sex, - age=age + age=age, + entrycategory=coursestandard, ) record.save()