Merge branch 'feature/moreregattas' into develop
This commit is contained in:
@@ -763,6 +763,7 @@ class VirtualRaceSelectForm(forms.Form):
|
||||
choices = get_countries()
|
||||
)
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(VirtualRaceSelectForm, self).__init__(*args, **kwargs)
|
||||
self.fields['country'] = forms.ChoiceField(
|
||||
|
||||
+6
-5
@@ -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')
|
||||
|
||||
+11
-10
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -87,13 +87,29 @@
|
||||
<tr>
|
||||
<td>
|
||||
{% if completeness|lookup:ps.id == 'not done' %}
|
||||
{% if ps.sessiontype != 'race' %}
|
||||
<a class="white dot" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}/session/{{ ps.id }}"> </a>
|
||||
{% else %}
|
||||
<a class="white dot" href="/rowers/virtualevent/{{ ps.id }}/submit"> </a>
|
||||
{% endif %}
|
||||
{% elif completeness|lookup:ps.id == 'completed' %}
|
||||
{% if ps.sessiontype != 'race' %}
|
||||
<a class="green dot" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}/session/{{ ps.id }}"> </a>
|
||||
{% else %}
|
||||
<a class="green dot" href="/rowers/virtualevent/{{ ps.id }}/submit"> </a>
|
||||
{% endif %}
|
||||
{% elif completeness|lookup:ps.id == 'partial' %}
|
||||
{% if ps.sessiontype != 'race' %}
|
||||
<a class="orange dot" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}/session/{{ ps.id }}"> </a>
|
||||
{% else %}
|
||||
<a class="orange dot" href="/rowers/virtualevent/{{ ps.id }}/submit"> </a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if ps.sessiontype != 'race' %}
|
||||
<a class="red dot" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}/session/{{ ps.id }}"> </a>
|
||||
{% else %}
|
||||
<a class="red dot" href="/rowers/virtualevent/{{ ps.id }}/submit"> </a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td> {{ ps.startdate|date:"Y-m-d" }} </td>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<p>
|
||||
<table width="100%" class="listtable shortpadded">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Event</th>
|
||||
<th>Country</th>
|
||||
<th>Course</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for race in races %}
|
||||
<tr>
|
||||
<td>{{ race.startdate }}</td>
|
||||
<td><a href="/rowers/virtualevent/{{ race.id }}">{{ race.name }}</a></td>
|
||||
<td>{{ race.course.country }}</td>
|
||||
<td>{{ race.course.name }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
@@ -48,7 +48,7 @@
|
||||
<th>Contact Phone</th><td>{{ race.contact_phone }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Comment</th><td>{{ race.comment }}</td>
|
||||
<th>Comment</th><td>{{ race.comment|linebreaks }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -57,11 +57,12 @@
|
||||
<div id="registerbuttons">
|
||||
{% if request.user.is_anonymous %}
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
{% else %}
|
||||
<p>
|
||||
See race rules below.
|
||||
See race rules below. Participation to this race is free,
|
||||
unless specified differently in the race comment above.
|
||||
</p>
|
||||
<p>
|
||||
{% for button in buttons %}
|
||||
@@ -109,7 +110,7 @@
|
||||
<tr>
|
||||
<td>{{ forloop.counter }}</td>
|
||||
<td>
|
||||
<a href="/rowers/workout/{{ result.workout.id }}">
|
||||
<a href="/rowers/workout/{{ result.workoutid }}">
|
||||
{{ result.username }}</a></td>
|
||||
<td>{{ result.teamname }}</th>
|
||||
<td>{{ result.age }}</td>
|
||||
@@ -156,8 +157,8 @@
|
||||
<td>{{ record.username }}
|
||||
<td>{{ record.teamname }}</td>
|
||||
<td>{{ record.boattype }}</td>
|
||||
<td>{{ record.weightcategory }}</td>
|
||||
<td>{{ record.age }}</td>
|
||||
<td>{{ record.weightcategory }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -166,6 +167,11 @@
|
||||
</div>
|
||||
<div id="rules">
|
||||
<h2>Rules</h2>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<p>
|
||||
@@ -199,6 +205,13 @@
|
||||
corrected times, please be sure your gender and birth date are set
|
||||
correctly in your user settings.
|
||||
</p>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid_4 omega">
|
||||
|
||||
@@ -5,6 +5,55 @@
|
||||
{% block title %}Rowsandall Virtual Racing{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script type='text/javascript'
|
||||
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
|
||||
</script>
|
||||
<script>
|
||||
|
||||
function submit_form() {
|
||||
console.log("form changed");
|
||||
var frm = $("#raceform");
|
||||
|
||||
var data = new FormData(frm[0]);
|
||||
|
||||
$.ajax({
|
||||
url: "/rowers/virtualevents",
|
||||
type: "POST",
|
||||
contentType: false,
|
||||
processData: false,
|
||||
data: data,
|
||||
|
||||
success: function(data) {
|
||||
console.log("got something back");
|
||||
console.log(data)
|
||||
|
||||
$('#racelist').html(data)
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
|
||||
console.log("CSRF token",csrftoken);
|
||||
|
||||
function csrfSafeMethod(method) {
|
||||
// these HTTP methods do not require CSRF protection
|
||||
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
||||
}
|
||||
$.ajaxSetup({
|
||||
beforeSend: function(xhr, settings) {
|
||||
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
|
||||
xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
}
|
||||
}
|
||||
});
|
||||
$("#raceform").on('change', function(evt) {
|
||||
submit_form();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -19,7 +68,7 @@
|
||||
</div>
|
||||
|
||||
<div class="grid_12 alpha">
|
||||
<form enctype="multipart/form-data" method="post">
|
||||
<form id="raceform" enctype="multipart/form-data" method="post">
|
||||
<div class="grid_8 alpha">
|
||||
{{ form.as_table }}
|
||||
{% csrf_token %}
|
||||
@@ -30,29 +79,8 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="grid_12 alpha">
|
||||
<p>
|
||||
<table width="100%" class="listtable shortpadded">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Event</th>
|
||||
<th>Country</th>
|
||||
<th>Course</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for race in races %}
|
||||
<tr>
|
||||
<td>{{ race.startdate }}</td>
|
||||
<td><a href="/rowers/virtualevent/{{ race.id }}">{{ race.name }}</a></td>
|
||||
<td>{{ race.course.country }}</td>
|
||||
<td>{{ race.course.name }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
<div class="grid_12 alpha" id="racelist">
|
||||
{% include 'racelist.html' %}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
+16
-9
@@ -13317,13 +13317,17 @@ def plannedsession_deleteconfirm_view(request,id=0):
|
||||
)
|
||||
|
||||
def virtualevents_view(request):
|
||||
is_ajax = False
|
||||
if request.is_ajax():
|
||||
is_ajax = True
|
||||
|
||||
# default races
|
||||
races = VirtualRace.objects.filter(
|
||||
startdate__gte=datetime.date.today()
|
||||
).order_by("startdate","start_time")
|
||||
|
||||
r = getrower(request.user)
|
||||
if not request.user.is_anonymous():
|
||||
r = getrower(request.user)
|
||||
|
||||
if request.method == 'POST':
|
||||
# process form
|
||||
@@ -13367,11 +13371,15 @@ def virtualevents_view(request):
|
||||
|
||||
form = VirtualRaceSelectForm()
|
||||
|
||||
|
||||
if is_ajax:
|
||||
return render(request,'racelist.html',
|
||||
{ 'races':races,
|
||||
})
|
||||
|
||||
return render(request,'virtualevents.html',
|
||||
{ 'races':races,
|
||||
'form':form,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
def virtualevent_view(request,id=0):
|
||||
@@ -13407,18 +13415,17 @@ 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"
|
||||
|
||||
|
||||
|
||||
records = VirtualRaceResult.objects.filter(
|
||||
@@ -13494,7 +13501,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 +13546,7 @@ def virtualevent_register_view(request,id=0):
|
||||
{
|
||||
'form':form,
|
||||
'race':race,
|
||||
'rower':r,
|
||||
'rowerid':r.id,
|
||||
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user