Private
Public Access
1
0

You can organize fastest challenges and register but submission does not work yet

This commit is contained in:
Sander Roosendaal
2020-11-10 08:46:33 +01:00
parent ffb089a0c0
commit 26ae894c28
6 changed files with 299 additions and 1 deletions

View File

@@ -0,0 +1,117 @@
{% extends "newbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}New Virtual Challenge{% endblock %}
{% block main %}
<h1>New On-The-Water Virtual Challenge</h1>
<ul class="main-content">
<li class="grid_4">
<p>With this form, you can create a new virtual challenge. After you submit
the form, the challenge is created and will be visible to all users. From
that moment, only the site admin can delete the challenge
(admin@rowsandall.com). You can still edit the challenge until
the start of the challenge window.
</p>
</li>
<li class="grid_3">
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<p>
<table class="djangoform">
{{ form.as_table }}
</table>
</p>
<p>
{% csrf_token %}
<input type="submit" value="Save">
</p>
</form>
</li>
<li class="grid_1">
<p>
<ul>
<p>All times are local times in the time zone you select</p>
<p>Adding a contact phone number and email is not mandatory, but we
strongly recommend it.</p>
<p>If your event has a registration closure deadline, participants
have to enter (and can withdraw) before the registration closure time.</p>
<p>Participants can submit results until the evaluation closure time.</p>
<p>Until one hour after evaluation closure time, the challenge organizer
can review and reject submitted results ("disqualification"). If
you as the challenge organizer intend to use this functionality, it
is strongly recommended that you fill out a contact email or phone
number.
</p>
<p>
The participants can row this challenge on any course, and their fastest time
over the challenge distance (respectively the largest distance achieved over the
challenge duration) is automatically extracted from the workout. No
need to program a set piece.
</p>
<p>
Standard Times are a way to compare results in a race category with
a course record or golden standard for that event. A point score is calculated
which compares the participant's result with the standard. This offers an
engaging way to compete on points across different categories, boat types, and skill
levels.
If you select a Standard Times set from the drop-down list, race categories will
be limited to those in the selected set of Standard Times.
</p>
</ul>
</p>
</li>
</ul>
{% endblock %}
{% block scripts %}
<script type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
</script>
<script>
$( document ).ready(function() {
$('#id_registration_form').change(function(){
var value = $(this).val();
if (value == 'windowstart') {
$('#id_registration_closure_0').val($('#id_startdate').val());
$('#id_registration_closure_1').val($('#id_start_time').val());
} else if (value == 'windowend') {
$('#id_registration_closure_0').val($('#id_enddate').val());
$('#id_registration_closure_1').val($('#id_end_time').val());
} else if (value == 'deadline') {
$('#id_registration_closure_0').val($('#id_evaluation_closure_0').val());
$('#id_registration_closure_1').val($('#id_evaluation_closure_1').val());
}
});
});
</script>
{% endblock %}
{% block sidebar %}
{% include 'menu_racing.html' %}
{% endblock %}

View File

@@ -7,10 +7,15 @@
</li>
<li id="races-new">
<a href="/rowers/virtualevent/create/">
<i class="far fa-flag fa-fw"></i>&nbsp;New Challenge
<i class="far fa-flag fa-fw"></i>&nbsp;New Course Challenge
</a>
</li>
<li id="indoor-new">
<a href="/rowers/virtualevent/createfastest/">
<i class="far fa-flag fa-fw"></i>&nbsp;New Any Course Challenge
</a>
</li>
<li id="fastest-new">
<a href="/rowers/virtualevent/createindoor/">
<i class="far fa-flag fa-fw"></i>&nbsp;New Indoor Challenge
</a>

View File

@@ -27,6 +27,10 @@
<td><a href="/rowers/virtualevent/{{ race.id }}">{{ race.name }}</a></td>
{% if race.sessiontype == 'race' %}
<td>{{ race.course.country }}</td>
{% elif race.sessiontype == 'fastest_distance' %}
<td>Worldwide On-the-water Challenge</td>
{% elif race.sessiontype == 'fastest_time' %}
<td>Worldwide On-the-water Challenge</td>
{% else %}
<td>Worldwide Indoor Challenge</td>
{% endif %}

View File

@@ -96,6 +96,14 @@
<tr>
<th>Course</th><td><a href="/rowers/courses/{{ race.course.id }}">{{ race.course }}</a></td>
</tr>
{% elif race.sessiontype == 'fastest_time' %}
<tr>
<th>Time Challenge</th><td>To be rowed on the water</td>
</tr>
{% elif race.sessiontype == 'fastest_distance' %}
<tr>
<th>Distance Challenge</th><td>To be rowed on the water</td>
</tr>
{% else %}
<tr>
<th>Indoor Race</th><td>To be rowed on a Concept2 ergometer</td>
@@ -586,6 +594,21 @@
You cannot submit results rowed
on other bodies of water.
</p>
{% elif race.sessiontype == 'fastest_time' %}
<p>
This on-the-water challenge asks you to try to get
as far as you can over the
race duration. It automatically finds the fastest interval
of the given duration
in your entire workout.
</p>
{% elif race.sessiontype == 'fastest_distance' %}
<p>
This on-the-water challenge asks you to try row as hard
as you can over a set distance.
It automatically finds the fastest interval of the given length
in your entire workout.
</p>
{% else %}
<p>
Indoor challenges are open for all, wherever you live.

View File

@@ -262,6 +262,8 @@ urlpatterns = [
re_path(r'^virtualevents/$',views.virtualevents_view,name='virtualevents_view'),
re_path(r'^virtualevent/create/$',views.virtualevent_create_view,name='virtualevent_create_view'),
re_path(r'^virtualevent/createindoor/$',views.indoorvirtualevent_create_view,name='indoorvirtualevent_create_view'),
re_path(r'^virtualevent/createfastest/$',views.fastestvirtualevent_create_view,
name='fastestvirtualevent_create_view'),
re_path(r'^raceregistration/togglenotification/(?P<id>\d+)/$',
views.virtualevent_toggle_email_view,name='virtualevent_toggle_email_view'),
re_path(r'^indoorraceregistration/togglenotification/(?P<id>\d+)/$',

View File

@@ -2706,6 +2706,153 @@ def indoorvirtualevent_create_view(request):
})
@login_required()
def fastestvirtualevent_create_view(request):
r = getrower(request.user)
if request.method == 'POST':
racecreateform = IndoorVirtualRaceForm(request.POST)
if racecreateform.is_valid():
cd = racecreateform.cleaned_data
startdate = cd['startdate']
start_time = cd['start_time']
enddate = cd['enddate']
end_time = cd['end_time']
comment = cd['comment']
sessionunit = cd['sessionunit']
sessionvalue = cd['sessionvalue']
name = cd['name']
registration_form = cd['registration_form']
registration_closure = cd['registration_closure']
evaluation_closure = cd['evaluation_closure']
contact_phone = cd['contact_phone']
contact_email = cd['contact_email']
coursestandards = cd['coursestandards']
# correct times
timezone_str = cd['timezone']
startdatetime = datetime.datetime.combine(startdate,start_time)
enddatetime = datetime.datetime.combine(enddate,end_time)
startdatetime = pytz.timezone(timezone_str).localize(
startdatetime
)
enddatetime = pytz.timezone(timezone_str).localize(
enddatetime
)
evaluation_closure = pytz.timezone(timezone_str).localize(
evaluation_closure.replace(tzinfo=None)
)
if registration_form == 'manual':
try:
registration_closure = pytz.timezone(
timezone_str
).localize(
registration_closure.replace(tzinfo=None)
)
except AttributeError:
registration_closure = startdatetime
elif registration_form == 'windowstart':
registration_closure = startdatetime
elif registration_form == 'windowend':
registration_closure = enddatetime
else:
registration_closure = evaluation_closure
if sessionunit == 'min':
sessionmode = 'time'
sessiontype = 'fastest_time'
else:
sessionmode = 'distance'
sessiontype = 'fastest_distance'
vs = VirtualRace(
name=name,
startdate=startdate,
preferreddate = startdate,
start_time = start_time,
enddate=enddate,
end_time=end_time,
comment=comment,
sessiontype = sessiontype,
sessionunit = sessionunit,
sessionmode = sessionmode,
sessionvalue = sessionvalue,
course=None,
timezone=timezone_str,
coursestandards=coursestandards,
evaluation_closure=evaluation_closure,
registration_closure=registration_closure,
contact_phone=contact_phone,
contact_email=contact_email,
country = 'Indoor',
manager=request.user,
)
vs.save()
# create Site Announcement & Tweet
if settings.DEBUG or settings.TESTING:
dotweet = False
elif 'dev' in settings.SITE_URL:
dotweet = False
else:
dotweet = True
announcementshort = "New Virtual Challenge on rowsandall.com: {name}".format(
name = name,
)
announcement = announcementshort + " {siteurl}/rowers/virtualevent/{raceid}/".format(
siteurl = SITE_URL,
raceid = vs.id
)
if len(announcement)>250:
announcement = announcementshort
sa = SiteAnnouncement(
announcement = announcement,
dotweet = dotweet
)
sa.save()
url = reverse('virtualevents_view')
return HttpResponseRedirect(url)
else:
racecreateform = IndoorVirtualRaceForm(timezone=r.defaulttimezone)
breadcrumbs = [
{
'url':reverse('virtualevents_view'),
'name': 'Challenges'
},
{
'url':reverse('indoorvirtualevent_create_view',
),
'name': 'New Indoor Virtual Regatta'
},
]
return render(request,'fastestvirtualeventcreate.html',
{
'form':racecreateform,
'breadcrumbs':breadcrumbs,
'rower':r,
'active':'nav-racing',
})
@login_required()
def virtualevent_create_view(request):
r = getrower(request.user)