diff --git a/rowers/models.py b/rowers/models.py index 25749a58..148c7055 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -920,6 +920,7 @@ class PlannedSession(models.Model): ('test','Mandatory Test'), ('cycletarget','Cycle Target'), ('coursetest','OTW test over a course'), + ('race','Virtual Race'), ) sessionmodechoices = ( @@ -1037,14 +1038,14 @@ class PlannedSession(models.Model): self.sessionmode = 'distance' self.sessionunit = 'm' self.criterium = 'exact' - if self.sessiontype == 'coursetest': + if self.sessiontype == 'coursetest' or self.sessiontype == 'race': self.sessionmode = 'distance' self.sessionunit = 'm' self.criterium = 'none' if self.course == None: self.course = GeoCourse.objects.all()[0] self.sessionvalue = course_length(self.course) - elif self.sessiontype != 'coursetest': + elif self.sessiontype != 'coursetest' and self.sessiontype != 'race': self.course = None if self.enddate < self.startdate: @@ -1326,11 +1327,11 @@ def auto_delete_strokedata_on_delete(sender, instance, **kwargs): # Virtual Race results (for keeping results when workouts are deleted) class VirtualRaceResult(models.Model): - user = models.ForeignKey(Rower) - teamname = models.CharField(max_length=20,verbose_name = 'Team Name', + userid = models.IntegerField(default=0) + teamname = models.CharField(max_length=80,verbose_name = 'Team Name', blank=True,null=True) username = models.CharField(max_length=150) - workout = models.ForeignKey(Workout,blank=True,null=True) + workoutid = models.IntegerField(null=True) weightcategory = models.CharField(default="hwt",max_length=10, choices=weightcategories, verbose_name='Weight Category') diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 4a38e89b..c90dc5a7 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -48,7 +48,7 @@ def add_workouts_plannedsession(ws,ps,r): ids = [w.id for w in wold] + [w.id for w in ws] ids = list(set(ids)) - if len(ids)>1 and ps.sessiontype in ['test','coursetest']: + if len(ids)>1 and ps.sessiontype in ['test','coursetest','race']: errors.append('For tests, you can only attach one workout') return result,comments,errors @@ -271,7 +271,7 @@ def is_session_complete_ws(ws,ps): if not completiondate: completiondate = ws.reverse()[0].date return ratio,'partial',completiondate - elif ps.sessiontype == 'coursetest': + elif ps.sessiontype in ['coursetest','race']: if ps.course: ( coursetime, @@ -615,8 +615,8 @@ def add_rower_race(r,race): def remove_rower_race(r,race): race.rower.remove(r) - records = VirtualRaceResult.objects.filter(user=r, - workout__isnull=True, + records = VirtualRaceResult.objects.filter(userid=r.id, + workoutid__isnull=True, race=race) for r in records: @@ -659,7 +659,7 @@ def add_workout_race(ws,race,r): ids = [w.id for w in ws] ids = list(set(ids)) - if len(ids)>1 and race.sessiontype in ['test','coursetest']: + if len(ids)>1 and race.sessiontype in ['test','coursetest','race']: errors.append('For tests, you can only attach one workout') return result,comments,errors @@ -693,7 +693,7 @@ def add_workout_race(ws,race,r): duration = totaltime_sec_to_string(coursetime) records = VirtualRaceResult.objects.filter( - user=r, + userid=r.id, race=race ) @@ -708,18 +708,19 @@ def add_workout_race(ws,race,r): return result,comments, errors record.coursecompleted=coursecompleted - record.workout=ws[0] + record.workoutid=ws[0].id record.duration = duration record.save() - + add_workouts_plannedsession(ws,race,r) return result,comments,errors def delete_race_result(workout,race): - results = VirtualRaceResult.objects.filter(workout=workout,race=race) + results = VirtualRaceResult.objects.filter(workoutid=workout.id,race=race) for r in results: - r.delete() + r.workoutid = None + r.save() diff --git a/rowers/templates/plannedsessions.html b/rowers/templates/plannedsessions.html index e84ad8bc..3d8f3f42 100644 --- a/rowers/templates/plannedsessions.html +++ b/rowers/templates/plannedsessions.html @@ -87,13 +87,29 @@ {% if completeness|lookup:ps.id == 'not done' %} + {% if ps.sessiontype != 'race' %}   + {% else %} +   + {% endif %} {% elif completeness|lookup:ps.id == 'completed' %} + {% if ps.sessiontype != 'race' %}   + {% else %} +   + {% endif %} {% elif completeness|lookup:ps.id == 'partial' %} + {% if ps.sessiontype != 'race' %}   {% else %} +   + {% endif %} + {% else %} + {% if ps.sessiontype != 'race' %}   + {% else %} +   + {% endif %} {% endif %} {{ ps.startdate|date:"Y-m-d" }} diff --git a/rowers/templates/virtualevent.html b/rowers/templates/virtualevent.html index 6a56f1f6..04610edf 100644 --- a/rowers/templates/virtualevent.html +++ b/rowers/templates/virtualevent.html @@ -48,7 +48,7 @@ Contact Phone{{ race.contact_phone }} - Comment{{ race.comment }} + Comment{{ race.comment|linebreaks }} @@ -57,11 +57,12 @@
{% if request.user.is_anonymous %}

- Registered users of rowsandall.com can participate in this event. + Registered users of rowsandall.com can participate in this event. Participation is free, unless specified differently in the race comment above.

{% else %}

- See race rules below. + See race rules below. Participation to this race is free, + unless specified differently in the race comment above.

{% for button in buttons %} @@ -109,7 +110,7 @@ {{ forloop.counter }} - + {{ result.username }} {{ result.teamname }} {{ result.age }} @@ -156,8 +157,8 @@ {{ record.username }} {{ record.teamname }} {{ record.boattype }} - {{ record.weightcategory }} {{ record.age }} + {{ record.weightcategory }} {% endfor %} @@ -166,6 +167,11 @@

Rules

+

+ Virtual races are intended as an informal way to add a + competitive element to training and as a quick way to set + up and manage small regattas. +

As a rowsandall.com user, you can register to take part in this event. @@ -180,7 +186,7 @@ After the start of the race window and before the submission deadline, you can submit results by linking the race to one of your uploaded workouts. The workout start time must be within the race window - and your trajectory must pass through the blue polygons on the course + and your course must pass through the blue polygons on the course map (in the right order), for your result to be valid.

@@ -199,6 +205,13 @@ corrected times, please be sure your gender and birth date are set correctly in your user settings.

+

+ Virtual races are intended as an informal way to add a + competitive element to training. Virtual races are not + refereed or staffed to provide for participants safety. + Individual participants are entirely responsible for their + safety while participating in a virtual race. +

diff --git a/rowers/views.py b/rowers/views.py index ec678904..20509a85 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -13407,16 +13407,15 @@ def virtualevent_view(request,id=0): results = VirtualRaceResult.objects.filter( race=race, - workout__isnull=False, + workoutid__isnull=False, ).order_by("duration") # to-do - add DNS dns = [] if timezone.now() > race.evaluation_closure: - print "aap" dns = VirtualRaceResult.objects.filter( race=race, - workout__isnull=True, + workoutid__isnull=True, ) print dns[0].username,"noot" @@ -13494,7 +13493,7 @@ def virtualevent_register_view(request,id=0): age = calculate_age(r.birthdate) record = VirtualRaceResult( - user=r, + userid=r.id, teamname=teamname, race=race, username = u'{f} {l}'.format( @@ -13539,7 +13538,7 @@ def virtualevent_register_view(request,id=0): { 'form':form, 'race':race, - 'rower':r, + 'rowerid':r.id, })