Private
Public Access
1
0

race entry self service

This commit is contained in:
Sander Roosendaal
2020-06-23 21:48:33 +02:00
parent 765d8052aa
commit ce51bbc26c
5 changed files with 388 additions and 25 deletions

View File

@@ -3002,6 +3002,34 @@ class VirtualRaceResult(models.Model):
acceptsocialmedia = models.BooleanField(default=True,
verbose_name = 'I agree with sharing my name in challenge related social media posts (unchecking this does not prevent you from participation)')
def isduplicate(self,other):
if self.userid != other.userid:
return False
if self.weightcategory != other.weightcategory:
return False
if self.adaptiveclass != other.adaptiveclass:
return False
if self.skillclass != other.skillclass:
return False
if self.race != other.race:
return False
if self.boatclass != other.boatclass:
return False
if self.boattype != other.boattype:
return False
if self.sex != other.sex:
return False
if self.entrycategory is not None and other.entrycategory is not None:
if self.entrycategory != other.entrycategory:
return False
elif self.entrycategory is None and other.entrycateogry is not None:
return False
elif self.entrycategory is not None and other.entrycategory is None:
return False
return True
def __str__(self):
rr = Rower.objects.get(id=self.userid)
name = '{u1} {u2}'.format(
@@ -3080,6 +3108,31 @@ class IndoorVirtualRaceResult(models.Model):
acceptsocialmedia = models.BooleanField(default=True,
verbose_name = 'I agree with sharing my name in challenge related social media posts (unchecking this does not prevent you from participation)')
def isduplicate(self,other):
if self.userid != other.userid:
return False
if self.weightcategory != other.weightcategory:
return False
if self.adaptiveclass != other.adaptiveclass:
return False
if self.skillclass != other.skillclass:
return False
if self.race != other.race:
return False
if self.boatclass != other.boatclass:
return False
if self.sex != other.sex:
return False
if self.entrycategory is not None and other.entrycategory is not None:
if self.entrycategory != other.entrycategory:
return False
elif self.entrycategory is None and other.entrycategory is not None:
return False
elif self.entrycategory is not None and other.entrycategory is None:
return False
return True
def __str__(self):
rr = Rower.objects.get(id=self.userid)
name = '{u1} {u2}'.format(

View File

@@ -0,0 +1,71 @@
{% extends "newbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}Register for a Virtual Race{% endblock %}
{% block meta %}
<script type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
</script>
<script type='text/javascript'
src='https://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js'>
</script>
<script>
</script>
{% endblock %}
{% block main %}
<h1>Change your entry for {{ race.name }}</h1>
<form id="race_register_form"
method="post">
<div class="grid_12 alpha">
<p>If you are participating in a single, we will take the age and weight
value from your user settings. For other boat types, please fill out
crew weight class and average age.
</p>
<p>
You will register as a crew with the gender of your user settings. If
your user settings have gender "not specified", you will be registered
as a Male crew. Check the "Mixed gender" check box to register as a
mixed gender crew (except for 1x where this check box does nothing).
</p>
<p>
The challenge organizer may want to publish about the challenge on social media and
use your name in the results. If you do not want your name to appear on social media,
you can let this know by unchecking the check box in the form.
</p>
{% if race.coursestandards %}
<p>This race uses standard times and limits the race groups to those where
standard times exist. The "Group" form choice will overrule other selections you
make in the form (boat type, weight, etc) and your entry will be rejected
if the age and gender doesn't match.
</p>
<p>
You can check the valid race groups and standard times <a target="_" href="/rowers/standards/{{ race.coursestandards.id }}/">here</a>.
</p>
{% endif %}
<div class="grid_6 alpha">
<table width="100%">
{{ form.as_table }}
</table>
</div>
</div>
{% csrf_token %}
<input class="button" type="submit" value="Submit">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
{% block sidebar %}
{% include 'menu_racing.html' %}
{% endblock %}

View File

@@ -263,14 +263,23 @@
</li>
<li class="grid_2">
<div id="results">
<p>
{% if race|is_final %}
<h2>Final Results</h2>
{% else %}
<h2>Results</h2>
{% endif %}
</p>
{% if results or dns or dnf %}
<a href="/rowers/virtualevent/{{ race.id }}/compare"
title="Compare the workouts of all competitors"><i class="fas fa-chart-line fa-fw"></i></a>
{% if race.sessiontype == 'race' %}
<a href="/rowers/virtualevent/{{ race.id }}/mapcompare"
title="Compare the courses taken by the competitors"><i class="fas fa-route fa-fw"></i></a>
{% endif %}
{% if race.manager == request.user %}
<a href="/rowers/virtualevent/{{ race.id }}/download"
title="Download Results"><i class="fas fa-file-download fa-fw"></i></a>
<p>
<table class="listtable shortpadded" width="100%">
<thead>
@@ -330,14 +339,20 @@
<td>{{ result.points|sigdig:4 }}</td>
{% endif %}
<td>
<a href="/rowers/workout/{{ result.workoutid|encode }}/view/entry/{{ result.id }}/">
Details</a>
<a title="Details" href="/rowers/workout/{{ result.workoutid|encode }}/view/entry/{{ result.id }}/">
<i class="fas fa-search-plus fa-fw"></i></a>
</td>
<td>
{% if result.userid == request.user.rower.id and not race|is_final %}
<a title="Edit" href="/rowers/virtualevent/{{ race.id }}/register/edit/{{ result.id }}">
<i class="fas fa-pencil-alt fa-fw"></i>
</a>
{% endif %}
</td>
<td>
{% if race.manager == request.user and not race|is_final %}
<a href="/rowers/virtualevent/{{ race.id }}/disqualify/{{ result.id }}/">
Disqualify
<a title="Disqualify" href="/rowers/virtualevent/{{ race.id }}/disqualify/{{ result.id }}/">
<i class="fas fa-flag-alt fa-fw"></i>
</a>
{% else %}
&nbsp;
@@ -345,8 +360,8 @@
</td>
<td>
{% if result.userid == request.user.rower.id and not race|is_final %}
<a href="/rowers/virtualevent/{{ race.id }}/withdrawresult/{{ result.id }}">
Remove
<a title="Remove" href="/rowers/virtualevent/{{ race.id }}/withdrawresult/{{ result.id }}">
<i class="fas fa-trash-alt fa-fw"></i>
</a>
{% endif %}
</td>
@@ -380,7 +395,7 @@
<td>DNF</td>
<td>
<a href="/rowers/workout/{{ result.workoutid|encode }}/view/entry/{{ result.id }}/">
Details</a>
<i class="fas fa-search-plus fa-fw"></i></a>
</td>
</tr>
{% endfor %}
@@ -415,19 +430,6 @@
</tbody>
</table>
</p>
<p>
<a href="/rowers/virtualevent/{{ race.id }}/compare"
title="Compare the workouts of all competitors">Compare Results</a>
{% if race.sessiontype == 'race' %}
<a href="/rowers/virtualevent/{{ race.id }}/mapcompare"
title="Compare the courses taken by the competitors">Compare Course</a>
{% endif %}
</p>
{% if race.manager == request.user %}
<p>
<a href="/rowers/virtualevent/{{ race.id }}/download"
title="Download Results">Download Results</a>
</p>
{% endif %}
{% else %}
<p>
@@ -506,11 +508,21 @@
{% endif %}
</td>
{% endif %}
{% if record.userid == rower.id and 'withdrawbutton' in buttons %}
{% if record.userid == request.user.rower.id and not race|is_final %}
<td>
<a href="/rowers/virtualevent/{{ race.id }}/withdraw/{{ record.id }}" >Withdraw</a>
<a title="Edit" href="/rowers/virtualevent/{{ race.id }}/register/edit/{{ record.id }}/">
<i class="fas fa-pencil-alt fa-fw"></i>
</a>
</td>
{% endif %}
{% if record.userid == rower.id and 'withdrawbutton' in buttons %}
<td>
<a title="Withdraw" href="/rowers/virtualevent/{{ race.id }}/withdraw/{{ record.id }}" >
<i class="fas fa-trash-alt fa-fw"></i>
</a>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>

View File

@@ -186,6 +186,8 @@ urlpatterns = [
re_path(r'^virtualevent/(?P<id>\d+)/editindoor/$',views.indoorvirtualevent_edit_view,name='indoorvirtualevent_edit_view'),
re_path(r'^virtualevent/(?P<id>\d+)/register/$',views.virtualevent_register_view,name='virtualevent_register_view'),
re_path(r'^virtualevent/(?P<id>\d+)/registerindoor/$',views.indoorvirtualevent_register_view,name='indoorvirtualevent_register_view'),
re_path(r'^virtualevent/(?P<id>\d+)/register/edit/(?P<entryid>\d+)/$',views.virtualevent_entry_edit_view,
name='virtualevent_entry_edit_view'),
re_path(r'^virtualevent/(?P<id>\d+)/adddiscipline/$',views.virtualevent_addboat_view,name='virtualevent_addboat_view'),
re_path(r'^virtualevent/(?P<id>\d+)/withdraw/(?P<recordid>\d+)/$',views.virtualevent_withdraw_view,name='virtualevent_withdraw_view'),
re_path(r'^virtualevent/(?P<id>\d+)/withdraw/$',views.virtualevent_withdraw_view,name='virtualevent_withdraw_view'),

View File

@@ -3103,3 +3103,228 @@ def addfollower_view(request,id=0):
'breadcrumbs':breadcrumbs,
}
)
@login_required()
def virtualevent_entry_edit_view(request,id=0,entryid=0):
r = getrower(request.user)
try:
race = VirtualRace.objects.get(id=id)
except VirtualRace.DoesNotExist:
raise Http404("Virtual Challenge does not exist")
if not race_can_submit(r,race):
messages.error(request,'You cannot change your entries for this challenge')
url = reverse('virtualevent_view',
kwargs={'id':race.id}
)
return HttpResponseRedirect(r,race)
categories = None
if race.coursestandards is not None:
categories = CourseStandard.objects.filter(
standardcollection=race.coursestandards).order_by("name")
if race.sessiontype == 'race':
resultobj = VirtualRaceResult
formobj = VirtualRaceResultForm
else:
resultobj = IndoorVirtualRaceResult
formobj = IndoorVirtualRaceResultForm
records = resultobj.objects.filter(
userid = r.id,
race=race
)
try:
record = resultobj.objects.get(id=entryid)
except resultobj.DoesNotExist:
raise Http404("Could not find your entry")
if request.method == 'POST':
form = formobj(request.POST,categories=categories)
if form.is_valid():
cd = form.cleaned_data
teamname = cd['teamname']
try:
boattype = cd['boattype']
except KeyError:
boattype = None
boatclass = cd['boatclass']
weightcategory = cd['weightcategory']
adaptiveclass = cd['adaptiveclass']
age = cd['age']
try:
mix = cd['mix']
except KeyError:
mix = None
acceptsocialmedia = cd['acceptsocialmedia']
sex = r.sex
if mix:
sex = 'mixed'
if boattype == '1x' and r.birthdate:
age = calculate_age(r.birthdate)
sex = r.sex
if sex == 'not specified':
sex = 'male'
coursestandard = None
referencespeed = 5.0
returnurl = reverse(virtualevent_entry_edit_view,
kwargs={'id':race.id,
'entryid':record.id})
if race.coursestandards is not None:
coursestandard = cd['entrycategory']
referencespeed = coursestandard.referencespeed
boattype = coursestandard.boattype
boatclass = coursestandard.boatclass
weightcategory = coursestandard.weightclass
adaptiveclass = coursestandard.adaptiveclass
skillclass = coursestandard.skillclass
if age < coursestandard.agemin:
messages.error(request,'You are younger than the minimum age for this group')
return HttpResponseRedirect(returnurl)
if age > coursestandard.agemax:
messages.error(request,'You are older than the maximum age for this group')
return HttpResponseRedirect(returnurl)
if sex == 'male' and coursestandard.sex != 'male':
messages.error(request,'Men are not allowed to enter this category')
return HttpResponseRedirect(returnurl)
if sex == 'mixed' and coursestandard.sex not in ['mixed','male']:
messages.error(request,'Mixed crews are not allowed to enter this category')
return HttpResponseRedirect(returnurl)
if record.workoutid:
try:
w = Workout.objects.get(id=record.workoutid)
except Workout.DoesNotExist:
w = None
if w is not None:
if boattype != w.boattype:
messages.error(request,'You cannot change boat type to a different one than your row')
return HttpResponseRedirect(returnurl)
if boatclass != w.workouttype:
messages.error(request,'You cannot change the class to a different one than your row')
return HttpResponseRedirect(returnurl)
if weightcategory != w.weightcategory:
messages.error(request,'You cannot change weight class to a different one than your row')
return HttpResponseRedirect(returnurl)
if adaptiveclass != w.adaptiveclass:
messages.error(request,'You cannot change adaptive class to a different one than your row')
return HttpResponseRedirect(returnurl)
else:
if boattype != record.boattype:
messages.error(request,'You cannot change boat type to a different one ')
return HttpResponseRedirect(returnurl)
if boatclass != record.workouttype:
messages.error(request,'You cannot change the class to a different one ')
return HttpResponseRedirect(returnurl)
if weightcategory != record.weightcategory:
messages.error(request,'You cannot change weight class to a different one ')
return HttpResponseRedirect(returnurl)
if adaptiveclass != record.adaptiveclass:
messages.error(request,'You cannot change adaptive class to a different one ')
return HttpResponseRedirect(returnurl)
if record.points != 0:
record.points = record.points*record.referencespeed/referencespeed
record.teamname = teamname
record.weightcategory=weightcategory
record.adaptiveclass=adaptiveclass
record.boatclass=boatclass
if race.sessiontype == 'race':
record.boattype = boattype
record.mix = mix
record.sex=sex
record.age=age
record.entrycategory=coursestandard
record.referencespeed=referencespeed
record.acceptsocialmedia=acceptsocialmedia
duplicates = False
for otherrecord in records:
if record.isduplicate(otherrecord):
duplicates = True
if duplicates:
messages.error(request,"You have already entered this group")
return HttpResponseRedirect(returnurl)
else:
record.save()
messages.info(
request,
"You have successfully altered your entry for this race. Good luck!"
)
url = reverse('virtualevent_view',
kwargs = {
'id':race.id
})
return HttpResponseRedirect(url)
else:
form = formobj(instance=record,categories=categories)
breadcrumbs = [
{
'url':reverse('virtualevents_view'),
'name': 'Challenges'
},
{
'url':reverse('virtualevent_view',
kwargs={'id':race.id}
),
'name': race.name
},
{
'url': reverse(virtualevent_entry_edit_view,
kwargs = {'id':race.id,
'entryid':entryid}
),
'name': 'Follow'
}
]
buttons = []
if not request.user.is_anonymous:
if race_can_register(r,race):
buttons += ['registerbutton']
if race_can_adddiscipline(r,race):
buttons += ['adddisciplinebutton']
if race_can_submit(r,race):
buttons += ['submitbutton']
if race_can_resubmit(r,race):
buttons += ['resubmitbutton']
if race_can_withdraw(r,race):
buttons += ['withdrawbutton']
if race_can_edit(r,race):
buttons += ['editbutton']
return render(request,'entryedit.html',
{
'form':form,
'active':'nav-racing',
'breadcrumbs':breadcrumbs,
'userid':r.user.id,
'race':race,
})