diff --git a/rowers/forms.py b/rowers/forms.py
index d6dc0cdd..c73770fc 100644
--- a/rowers/forms.py
+++ b/rowers/forms.py
@@ -1,6 +1,9 @@
from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple
-from rowers.models import Workout,Rower,Team,PlannedSession,GeoCourse
+from rowers.models import (
+ Workout,Rower,Team,PlannedSession,GeoCourse,
+ VirtualRace,VirtualRaceResult,IndoorVirtualRaceResult
+ )
from rowers.rows import validate_file_extension,must_be_csv,validate_image_extension,validate_kml
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
@@ -16,6 +19,7 @@ from utils import landingpages
from metrics import axes
+
# login form
class LoginForm(forms.Form):
username = forms.CharField()
@@ -254,6 +258,10 @@ class UploadOptionsForm(forms.Form):
makeprivate = forms.BooleanField(initial=False,required=False,
label='Make Workout Private')
+ submitrace = forms.ModelChoiceField(queryset=VirtualRace.objects.all(),
+ label='Submit as Race Result',
+ required=False)
+
landingpage = forms.ChoiceField(choices=nextpages,
initial='workout_edit_view',
label='After Upload, go to')
@@ -261,6 +269,28 @@ class UploadOptionsForm(forms.Form):
class Meta:
fields = ['make_plot','plottype','upload_toc2','makeprivate']
+ def __init__(self, *args, **kwargs):
+ self.request = kwargs.pop('request',None)
+ super(UploadOptionsForm, self).__init__(*args, **kwargs)
+ r = Rower.objects.get(user=self.request.user)
+ races = VirtualRace.objects.filter(
+ registration_closure__gt=timezone.now(),
+ sessiontype='indoorrace')
+ registrations = IndoorVirtualRaceResult.objects.filter(
+ race__in = races,
+ userid = r.id)
+
+ raceids = [r.race.id for r in registrations]
+
+ races = VirtualRace.objects.filter(
+ id__in=raceids
+ )
+
+ if races:
+ self.fields['submitrace'].queryset = races
+ else:
+ del self.fields['submitrace']
+
# The form to indicate additional actions to be performed immediately
# after a successful upload. This version allows the Team manager to select
# a team member
diff --git a/rowers/models.py b/rowers/models.py
index 10b84581..09a61c8b 100644
--- a/rowers/models.py
+++ b/rowers/models.py
@@ -2422,6 +2422,8 @@ class VirtualRaceResult(models.Model):
verbose_name='Gender')
age = models.IntegerField(null=True)
+ emailnotifications = models.BooleanField(default=True,
+ verbose_name = 'Receive race notifications by email')
def __unicode__(self):
rr = Rower.objects.get(id=self.userid)
@@ -2472,6 +2474,8 @@ class IndoorVirtualRaceResult(models.Model):
verbose_name='Gender')
age = models.IntegerField(null=True)
+ emailnotifications = models.BooleanField(default=True,
+ verbose_name = 'Receive race notifications by email')
def __unicode__(self):
rr = Rower.objects.get(id=self.userid)
@@ -2686,7 +2690,7 @@ class WorkoutForm(ModelForm):
startdate__lte=workout.date,
enddate__gte=workout.date,
).order_by("preferreddate","startdate","enddate").exclude(
- sessiontype='race')
+ sessiontype__in=['race','indoorrace'])
if not sps:
del self.fields['plannedsession']
diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py
index c9b9232f..c152305c 100644
--- a/rowers/plannedsessions.py
+++ b/rowers/plannedsessions.py
@@ -20,7 +20,7 @@ from rowers.models import (
Rower, Workout,Team,
GeoCourse, TrainingMicroCycle,TrainingMesoCycle,TrainingMacroCycle,
TrainingPlan,PlannedSession,VirtualRaceResult,CourseTestResult,
- get_course_timezone, IndoorVirtualRaceResult
+ get_course_timezone, IndoorVirtualRaceResult,VirtualRace
)
from rowers.courses import get_time_course
@@ -33,6 +33,41 @@ import iso8601
from iso8601 import ParseError
from rowers.tasks import handle_check_race_course
+def get_indoorraces(workout):
+ races1 = VirtualRace.objects.filter(
+ registration_closure__gt=timezone.now(),
+ sessiontype='indoorrace',
+ startdate__lte=workout.date,
+ enddate__gte=workout.date,
+ sessionmode='distance',
+ sessionvalue=workout.distance)
+
+
+ if workout.duration.second != 0 and workout.duration.microsecond != 0:
+ duration = 60*workout.duration.hour+workout.duration.minute
+
+
+ races2 = VirtualRace.objects.filter(
+ registration_closure__gt=timezone.now(),
+ sessiontype='indoorrace',
+ startdate__lte=workout.date,
+ enddate__gte=workout.date,
+ sessionmode='time',
+ sessionvalue=duration)
+
+ races = races1 | races2
+ else:
+ races = races1
+
+ registrations = IndoorVirtualRaceResult.objects.filter(
+ race__in = races,
+ userid=workout.user.id)
+
+ races = [r.race for r in registrations]
+
+
+ return races
+
def get_todays_micro(plan,thedate=date.today()):
thismicro = None
@@ -729,10 +764,11 @@ def race_can_submit(r,race):
if is_complete == False:
return True
else:
- return False
+ return True
else:
return False
+ print 'pop'
return False
def race_can_resubmit(r,race):
@@ -970,6 +1006,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
record.duration = ws[0].duration
+
if ws[0].weightcategory != record.weightcategory:
errors.append('Your workout weight category did not match the weight category you registered')
return 0,comments, errors,0
@@ -993,7 +1030,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
record.coursecompleted = True
record.workoutid = ws[0].id
record.save()
-
+
add_workouts_plannedsession(ws,race,r)
diff --git a/rowers/tasks.py b/rowers/tasks.py
index 374cd509..d1f6855e 100644
--- a/rowers/tasks.py
+++ b/rowers/tasks.py
@@ -740,6 +740,66 @@ def handle_updatedps(useremail, workoutids, debug=False,**kwargs):
# send email when a breakthrough workout is uploaded
+@app.task
+def handle_sendemail_raceregistration(
+ useremail, username, registeredname, racename, raceid, **kwargs):
+
+ if 'debug' in kwargs:
+ debug = kwargs['debug']
+ else:
+ debug = True
+
+ subject = "A new competitor has registered for virtual race {n}".format(
+ n = racename
+ )
+
+ from_email = 'Rowsandall '
+
+ d = {
+ 'username':username,
+ 'registeredname':registeredname,
+ 'siteurl':siteurl,
+ 'racename':racename,
+ 'raceid':raceid,
+ }
+
+ res = send_template_email(from_email,[useremail],
+ subject,
+ 'raceregisteredemail.html',
+ d,**kwargs)
+
+ return 1
+
+@app.task
+def handle_sendemail_racesubmission(
+ useremail, username, registeredname, racename, raceid, **kwargs):
+
+ if 'debug' in kwargs:
+ debug = kwargs['debug']
+ else:
+ debug = True
+
+ subject = "A new result has been submitted for virtual race {n}".format(
+ n = racename
+ )
+
+ from_email = 'Rowsandall '
+
+ d = {
+ 'username':username,
+ 'siteurl':siteurl,
+ 'registeredname':registeredname,
+ 'racename':racename,
+ 'raceid':raceid,
+ }
+
+ res = send_template_email(from_email,[useremail],
+ subject,
+ 'racesubmissionemail.html',
+ d,**kwargs)
+
+ return 1
+
@app.task
def handle_send_disqualification_email(
useremail,username,reason,message, racename, **kwargs):
@@ -758,6 +818,7 @@ def handle_send_disqualification_email(
d = {
'username':username,
'reason':reason,
+ 'siteurl':siteurl,
'message': strip_tags(message),
'racename':racename,
}
diff --git a/rowers/templates/disqualificationemail.html b/rowers/templates/disqualificationemail.html
index 1c7dca91..c72af9fc 100644
--- a/rowers/templates/disqualificationemail.html
+++ b/rowers/templates/disqualificationemail.html
@@ -4,7 +4,8 @@
Unfortunately, the result that you have submitted
- for the virtual race {{ racename }}
+ for the virtual race
+ {{ racename }}
has been rejected by the race organizer.
diff --git a/rowers/templates/menu_racing.html b/rowers/templates/menu_racing.html
index 4a06ef2d..62c7c54f 100644
--- a/rowers/templates/menu_racing.html
+++ b/rowers/templates/menu_racing.html
@@ -15,15 +15,82 @@
New Indoor Race
+ {% if race %}
+ {% if reguest.user.is_anonymous %}
+
+ A new competitor has registered for the race {{ racename }}: {{ registeredname }}
+
+
+
+
+ You can check race participants and results on the race page on Rowsandall:
+ {{ racename }}
+
+
+
+ You are receiving this email because you are on the start list for this race.
+ If you do not wish to receive these notifications, you can switch them off
+ throught the link above.
+
+ One of your competitors, {{ registeredname }}, has submitted a result for {{ racename }}
+
+
+
+
+ Check out the results on the race page!
+ {{ racename }}
+
+
+
+ You are receiving this email because you are on the start list for this race.
+ If you do not wish to receive these notifications, you can switch them off
+ throught the link above.
+
+ If you don't have a data file, enter the results
+ manually. If you have a photo of the monitor with the
+ result, it is recommended to add this to the workout.
+