diff --git a/rowers/emails.py b/rowers/emails.py
index 7dfa16d1..826d43bb 100644
--- a/rowers/emails.py
+++ b/rowers/emails.py
@@ -45,6 +45,8 @@ env = Environment(loader = FileSystemLoader(["rowers/templates"]))
from django.contrib.staticfiles import finders
+
+
def textify(html):
# Remove html tags and continuous whitespaces
text_only = re.sub('[ \t]+', ' ', strip_tags(html))
diff --git a/rowers/forms.py b/rowers/forms.py
index 290e5f00..d6dc0cdd 100644
--- a/rowers/forms.py
+++ b/rowers/forms.py
@@ -30,6 +30,24 @@ class EmailForm(forms.Form):
botcheck = forms.CharField(max_length=5)
message = forms.CharField()
+disqualificationreasons = (
+ ('noimage','You did not attach a monitor screenshot or other photographic evidence as required'),
+ ('suspicious','We doubt that you rowed this in the right boat class or type'),
+ ('duplicate','This result looks like a duplicate entry'),
+ ('other','Other Reason'),
+)
+
+disqualifiers = {}
+for key, value in disqualificationreasons:
+ disqualifiers[key] = value
+
+class DisqualificationForm(forms.Form):
+
+ reason = forms.ChoiceField(required=True,
+ choices=disqualificationreasons,
+ widget = forms.RadioSelect,)
+
+ message = forms.CharField(required=True,widget=forms.Textarea)
class MetricsForm(forms.Form):
avghr = forms.IntegerField(required=False,label='Average Heart Rate')
@@ -892,8 +910,11 @@ class RaceResultFilterForm(forms.Form):
self.fields['boatclass'].choices = boatclasschoices
# boattype
- theboattypees = [record.boattype for record in records]
- theboattypees = list(set(theboattypees))
+ try:
+ theboattypees = [record.boattype for record in records]
+ theboattypees = list(set(theboattypees))
+ except AttributeError:
+ theboattypees = []
if len(theboattypees)<= 1:
del self.fields['boattype']
diff --git a/rowers/models.py b/rowers/models.py
index 3a711c35..88c96f5b 100644
--- a/rowers/models.py
+++ b/rowers/models.py
@@ -1664,6 +1664,7 @@ class PlannedSession(models.Model):
('cycletarget','Total for a time period'),
('coursetest','OTW test over a course'),
('race','Virtual Race'),
+ ('indoorrace','Indoor Virtual Race'),
)
sessionmodechoices = (
@@ -1772,7 +1773,7 @@ class PlannedSession(models.Model):
else:
self.sessionunit = 'None'
- if self.sessiontype == 'test':
+ if self.sessiontype == 'test' or self.sessiontype == 'indoorrace':
if self.sessionmode not in ['distance','time']:
if self.sessionvalue < 100:
self.sessionmode = 'time'
@@ -1937,7 +1938,126 @@ def get_course_timezone(course):
return timezone_str
+class IndoorVirtualRaceForm(ModelForm):
+ registration_closure = forms.SplitDateTimeField(widget=AdminSplitDateTime(),required=False)
+ evaluation_closure = forms.SplitDateTimeField(widget=AdminSplitDateTime(),required=True)
+ timezone = forms.ChoiceField(initial='UTC',
+ choices=[(x,x) for x in pytz.common_timezones],
+ label='Time Zone')
+
+ class Meta:
+ model = VirtualRace
+ fields = [
+ 'name',
+ 'startdate',
+ 'start_time',
+ 'enddate',
+ 'end_time',
+ 'timezone',
+ 'sessionvalue',
+ 'sessionunit',
+ 'registration_form',
+ 'registration_closure',
+ 'evaluation_closure',
+ 'comment',
+ 'contact_phone',
+ 'contact_email',
+ ]
+
+ dateTimeOptions = {
+ 'format': 'yyyy-mm-dd',
+ 'autoclose': True,
+ }
+
+ widgets = {
+ 'comment': forms.Textarea,
+ 'startdate': AdminDateWidget(),
+ 'enddate': AdminDateWidget(),
+ 'start_time': AdminTimeWidget(),
+ 'end_time': AdminTimeWidget(),
+ 'registration_closure':AdminSplitDateTime(),
+ 'evaluation_closure':AdminSplitDateTime(),
+ }
+
+ def __init__(self,*args,**kwargs):
+ super(IndoorVirtualRaceForm, self).__init__(*args, **kwargs)
+ self.fields['sessionunit'].choices = [('min','minutes'),('m','meters')]
+
+ def clean(self):
+ cd = self.cleaned_data
+ timezone_str = cd['timezone']
+
+ start_time = cd['start_time']
+ if start_time is None:
+ raise forms.ValidationError(
+ 'Must have start time',
+ code='missing_yparam1'
+ )
+ start_date = cd['startdate']
+ startdatetime = datetime.datetime.combine(start_date,start_time)
+ startdatetime = pytz.timezone(timezone_str).localize(
+ startdatetime
+ )
+
+ end_time = cd['end_time']
+ if end_time is None:
+ raise forms.ValidationError(
+ 'Must have end time',
+ code='missing endtime'
+ )
+
+ end_date = cd['enddate']
+ enddatetime = datetime.datetime.combine(end_date,end_time)
+ enddatetime = pytz.timezone(timezone_str).localize(
+ enddatetime
+ )
+
+ registration_closure = cd['registration_closure']
+
+ registration_form = cd['registration_form']
+
+ try:
+ evaluation_closure = cd['evaluation_closure']
+ except KeyError:
+ evaluation_closure = enddatetime+datetime.timedelta(days=1)
+ cd['evaluation_closure'] = evaluation_closure
+
+ 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 registration_closure <= timezone.now():
+ raise forms.ValidationError("Registration Closure cannot be in the past")
+
+
+ if startdatetime > enddatetime:
+ raise forms.ValidationError("The Start of the Race Window should be before the End of the Race Window")
+
+
+ if cd['evaluation_closure'] <= enddatetime:
+ raise forms.ValidationError("Evaluation closure deadline should be after the Race Window closes")
+
+ if cd['evaluation_closure'] <= timezone.now():
+ raise forms.ValidationError("Evaluation closure cannot be in the past")
+
+
+ return cd
+
+
class VirtualRaceForm(ModelForm):
course = forms.ModelChoiceField(queryset = GeoCourse.objects, empty_label=None)
registration_closure = forms.SplitDateTimeField(widget=AdminSplitDateTime(),required=False)
@@ -2309,6 +2429,54 @@ class VirtualRaceResult(models.Model):
s = self.sex,
)
+# Virtual Race results (for keeping results when workouts are deleted)
+class IndoorVirtualRaceResult(models.Model):
+ boatclasses = (type for type in mytypes.workouttypes if type[0] in mytypes.otetypes)
+ 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)
+ workoutid = models.IntegerField(null=True)
+ weightcategory = models.CharField(default="hwt",max_length=10,
+ choices=weightcategories,
+ verbose_name='Weight Category')
+ race = models.ForeignKey(VirtualRace)
+ duration = models.TimeField(default=datetime.time(1,0))
+ distance = models.IntegerField(default=0)
+ boatclass = models.CharField(choices=boatclasses,
+ max_length=40,
+ default='rower',
+ verbose_name = 'Ergometer Class')
+ coursecompleted = models.BooleanField(default=False)
+ sex = models.CharField(default="not specified",
+ max_length=30,
+ choices=sexcategories,
+ verbose_name='Gender')
+
+ age = models.IntegerField(null=True)
+
+ def __unicode__(self):
+ rr = Rower.objects.get(id=self.userid)
+ name = '{u1} {u2}'.format(
+ u1 = rr.user.first_name,
+ u2 = rr.user.last_name,
+ )
+ if self.teamname:
+ return u'Entry for {n} for "{r}" on {c} with {t} ({s})'.format(
+ n = name,
+ r = self.race,
+ t = self.teamname,
+ c = self.boatclass,
+ s = self.sex,
+ )
+ else:
+ return u'Entry for {n} for "{r}" on {c} ({s})'.format(
+ n = name,
+ r = self.race,
+ c = self.boatclass,
+ s = self.sex,
+ )
+
class CourseTestResult(models.Model):
userid = models.IntegerField(default=0)
@@ -2318,6 +2486,16 @@ class CourseTestResult(models.Model):
distance = models.IntegerField(default=0)
coursecompleted = models.BooleanField(default=False)
+class IndoorVirtualRaceResultForm(ModelForm):
+ class Meta:
+ model = IndoorVirtualRaceResult
+ fields = ['teamname','weightcategory','boatclass','age']
+
+
+ def __init__(self, *args, **kwargs):
+ super(IndoorVirtualRaceResultForm, self).__init__(*args, **kwargs)
+
+
class VirtualRaceResultForm(ModelForm):
class Meta:
model = VirtualRaceResult
diff --git a/rowers/mytypes.py b/rowers/mytypes.py
index e0b9fa7a..ad704756 100644
--- a/rowers/mytypes.py
+++ b/rowers/mytypes.py
@@ -225,6 +225,12 @@ otwtypes = (
'churchboat'
)
+otetypes = (
+ 'rower',
+ 'dynamic',
+ 'slides'
+ )
+
rowtypes = (
'water',
'rower',
diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py
index 3b274605..04f6c194 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
+ get_course_timezone, IndoorVirtualRaceResult
)
from rowers.courses import get_time_course
@@ -574,6 +574,56 @@ def update_plannedsession(ps,cd):
return 1,'Planned Session Updated'
+def update_indoorvirtualrace(ps,cd):
+ for attr, value in cd.items():
+ if attr == 'comment':
+ value.replace("\r\n", "
");
+ value.replace("\n", "
");
+ setattr(ps, attr, value)
+
+ timezone_str = cd['timezone']
+
+ # correct times
+
+ startdatetime = datetime.combine(cd['startdate'],cd['start_time'])
+ enddatetime = datetime.combine(cd['enddate'],cd['end_time'])
+
+ startdatetime = pytz.timezone(timezone_str).localize(
+ startdatetime
+ )
+ enddatetime = pytz.timezone(timezone_str).localize(
+ enddatetime
+ )
+ ps.evaluation_closure = pytz.timezone(timezone_str).localize(
+ ps.evaluation_closure.replace(tzinfo=None)
+ )
+
+ registration_form = cd['registration_form']
+ registration_closure = cd['registration_closure']
+ 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 = ps.evaluation_closure
+
+ ps.registration_closure = registration_closure
+
+ ps.timezone = timezone_str
+
+ ps.save()
+
+ return 1,'Virtual Race Updated'
+
def update_virtualrace(ps,cd):
for attr, value in cd.items():
if attr == 'comment':
@@ -630,8 +680,13 @@ def race_rower_status(r,race):
has_registered = False
is_complete = False
-
- vs = VirtualRaceResult.objects.filter(userid=r.id,race=race)
+
+ if race.sessiontype == 'race':
+ resultobj = VirtualRaceResult
+ else:
+ resultobj = IndoorVirtualRaceResult
+
+ vs = IndoorVirtualRaceResult.objects.filter(userid=r.id,race=race)
if vs:
has_registered = True
is_complete = vs[0].coursecompleted
@@ -708,6 +763,10 @@ def race_can_resubmit(r,race):
return False
def race_can_adddiscipline(r,race):
+
+ if race.sessiontype != 'race':
+ return False
+
records = VirtualRaceResult.objects.filter(
userid=r.id,
race=race)
@@ -766,7 +825,12 @@ def race_can_withdraw(r,race):
return True
def race_can_register(r,race):
- records = VirtualRaceResult.objects.filter(
+ if race.sessiontype == 'race':
+ recordobj = VirtualRaceResult
+ else:
+ recordobj = IndoorVirtualRaceResult
+
+ records = recordobj.objects.filter(
userid=r.id,
race=race)
@@ -798,13 +862,18 @@ def add_rower_race(r,race):
def remove_rower_race(r,race,recordid=None):
race.rower.remove(r)
+ if race.sessiontype == 'race':
+ recordobj = VirtualRaceResult
+ else:
+ recordobj = IndoorVirtualRaceResult
+
if recordid:
- records = VirtualRaceResult.objects.filter(userid=r.id,
+ records = recordobj.objects.filter(userid=r.id,
workoutid__isnull=True,
race=race,
id=recordid)
else:
- records = VirtualRaceResult.objects.filter(userid=r.id,
+ records = recordobj.objects.filter(userid=r.id,
workoutid__isnull=True,
race=race,)
for r in records:
@@ -813,6 +882,116 @@ def remove_rower_race(r,race,recordid=None):
return 1
# Low Level functions - to be called by higher level methods
+def add_workout_indoorrace(ws,race,r,recordid=0):
+ result = 0
+ comments = []
+ errors = []
+
+ start_time = race.start_time
+ start_date = race.startdate
+ startdatetime = datetime.combine(start_date,start_time)
+ startdatetime = pytz.timezone(race.timezone).localize(
+ startdatetime
+ )
+
+ end_time = race.end_time
+ end_date = race.enddate
+ enddatetime = datetime.combine(end_date,end_time)
+ enddatetime = pytz.timezone(race.timezone).localize(
+ enddatetime
+ )
+
+ # check if all sessions have same date
+ dates = [w.date for w in ws]
+ if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge','cycletarget']:
+ errors.append('For tests and training sessions, selected workouts must all be done on the same date')
+ return result,comments,errors,0
+
+ if len(ws)>1 and race.sessiontype == 'test':
+ errors.append('For tests, you can only attach one workout')
+ return result,comments,errors,0
+
+
+
+ ids = [w.id for w in ws]
+ ids = list(set(ids))
+
+ if len(ids)>1 and race.sessiontype in ['test','coursetest','race','indoorrace']:
+ errors.append('For tests, you can only attach one workout')
+ return result,comments,errors,0
+
+
+
+ username = r.user.first_name+' '+r.user.last_name
+ if r.birthdate:
+ age = calculate_age(r.birthdate)
+ else:
+ age = None
+
+ record = IndoorVirtualRaceResult.objects.get(
+ userid=r.id,
+ race=race,
+ id=recordid
+ )
+
+ records = IndoorVirtualRaceResult.objects.filter(
+ userid=r.id,
+ race=race,
+ workoutid = ws[0].id
+ )
+
+ if not record:
+ errors.append("Couldn't find this entry")
+ return result,comments,errors,0
+
+ if race.sessionmode == 'distance':
+ if ws[0].distance != race.sessionvalue:
+ errors.append('Your workout did not have the correct distance')
+ return 0,comments, errors, 0
+ else:
+ record.distance = ws[0].distance
+ record.duration = ws[0].duration
+ else:
+ t = ws[0].duration
+ seconds = t.second+t.minute*60.+t.hour*3600.+t.microsecond/1.e6
+ if seconds != race.sessionvalue*60.:
+ errors.append('Your workout did not have the correct duration')
+ return 0, comments, errors, 0
+ else:
+ record.distance = ws[0].distance
+ 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
+
+ # start adding sessions
+ if ws[0].startdatetime>=startdatetime and ws[0].startdatetime<=enddatetime:
+ ws[0].plannedsession = race
+ ws[0].save()
+ result += 1
+
+ else:
+ errors.append('Workout %i did not match the race window' % ws[0].id)
+ return result,comments,errors,0
+
+ if result>0:
+ for otherrecord in records:
+ otherrecord.workoutid = None
+ otherrecord.coursecompleted = False
+ otherrecord.save()
+
+ record.coursecompleted = True
+ record.workoutid = ws[0].id
+ record.save()
+
+ add_workouts_plannedsession(ws,race,r)
+
+
+ return result,comments,errors,0
+
+
def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
result = 0
comments = []
@@ -895,7 +1074,6 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
if result>0:
for otherrecord in records:
- print otherrecord
otherrecord.workoutid = None
otherrecord.coursecompleted = False
otherrecord.save()
diff --git a/rowers/tasks.py b/rowers/tasks.py
index f18c1ba8..f53d6dda 100644
--- a/rowers/tasks.py
+++ b/rowers/tasks.py
@@ -41,6 +41,22 @@ from django.utils.html import strip_tags
from utils import deserialize_list,ewmovingaverage,wavg
+from HTMLParser import HTMLParser
+class MLStripper(HTMLParser):
+ def __init__(self):
+ self.reset()
+ self.fed = []
+ def handle_data(self, d):
+ self.fed.append(d)
+ def get_data(self):
+ return ''.join(self.fed)
+
+def strip_tags(html):
+ s = MLStripper()
+ s.feed(html)
+ return s.get_data()
+
+
from rowers.dataprepnodjango import (
update_strokedata, new_workout_from_file,
getsmallrowdata_db, updatecpdata_sql,
@@ -721,6 +737,35 @@ def handle_updatedps(useremail, workoutids, debug=False,**kwargs):
# send email when a breakthrough workout is uploaded
+@app.task
+def handle_send_disqualification_email(
+ useremail,username,reason,message, racename, **kwargs):
+
+ if 'debug' in kwargs:
+ debug = kwargs['debug']
+ else:
+ debug = True
+
+ subject = "Your result for {n} has been disqualified on rowsandall.com".format(
+ n = racename
+ )
+
+ from_email = 'Rowsandall
+ Before you reject this race result, please carefully review it
+ using the information below. If you still want to reject the entry,
+ scroll down to the rejection form.
+
+ Do you want to disqualify this result?
+
+
+
+
+ Rower: {{ record.username }}
+
+
+ Name: {{ workout.name }}
+
+
+ Date: {{ workout.date }}
+
+ Time: {{ workout.starttime }}
+
+ Distance: {{ workout.distance }}m
+
+ Duration: {{ workout.duration |durationprint:"%H:%M:%S.%f" }}
+
+ Type: {{ workout.workouttype }}
+
+
+ Weight Category: {{ workout.weightcategory }}
+ Workout Summary
+
+
+ {{ workout.summary }}
+
+
+ Please select a reason and add a comment (mandatory). + Pressing 'Reject' disqualifies the submitted result. + An email will be sent to the rower. There is no "undo". +
++
+Dear {{ username }},
+ ++ Unfortunately, the result that you have submitted + for the virtual race {{ racename }} + has been rejected by the race organizer. +
+ ++ The reason for the rejection was: {{ reason }}. +
+ ++ The race organizer added the following explanation: +
+ +
+ {{ message }} +
+ ++ The decision to reject your result is the sole responsibility of + the race organizer. If you disagree with the decision, please do contact + him or her. +
+ ++ You are still registered for the race and can submit a result. +
+ ++ Best Regards, the Rowsandall Team +
+{% endblock %} + diff --git a/rowers/templates/indoorvirtualeventcreate.html b/rowers/templates/indoorvirtualeventcreate.html new file mode 100644 index 00000000..1492d6aa --- /dev/null +++ b/rowers/templates/indoorvirtualeventcreate.html @@ -0,0 +1,71 @@ +{% extends "newbase.html" %} +{% load staticfiles %} +{% load rowerfilters %} + +{% block title %}New Virtual Race{% endblock %} + +{% block main %} + +With this form, you can create a new virtual race. After you submit + the form, the race is created and will be visible to all users. From + that moment, only the site admin can delete the race + (admin@rowsandall.com). You can still edit the race until + the start of the race window. +
++
All times are local times in the time zone you select
+Adding a contact phone number and email is not mandatory, but we + strongly recommend it.
+If your event has a registration closure deadline, participants + have to enter (and can withdraw) before the registration closure time.
+Participants can submit results until the evaluation closure time.
+Until one hour after evaluation closure time, the race organizer + can review and reject submitted results ("disqualification"). If + you as the race organizer intend to use this functionality, it + is strongly recommended that you fill out a contact email or phone + number. +
++ If you require a screenshot of the PM monitor, do mention this + in the comment. +
+
@@ -32,11 +34,23 @@
| Course | {{ race.course }} | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Distance | {{ race.sessionvalue }} m | +Indoor Race | To be rowed on a Concept2 ergometer | +||||||
| Time Zone | {{ race.timezone }} | +||||||||
| + {{ race.sessionmode }} challenge + | {{ race.sessionvalue }} {{ race.sessionunit }} + | ||||||||
| Registration closure | @@ -81,38 +95,42 @@ {% for button in buttons %} {% if button == 'registerbutton' %}+ {% if race.sessiontype == 'race' %} | Class | Boat | + {% endif %}Time | Distance | Details | +{{ result.age }} | {{ result.sex }} | {{ result.weightcategory }} | + {% if race.sessiontype == 'race' %}{{ result.boatclass }} | {{ result.boattype }} | + {% endif %}{{ result.duration |durationprint:"%H:%M:%S.%f" }} | {{ result.distance }} m | Details | ++ {% if race.manager == request.user and not race|is_final %} + + Disqualify + + {% else %} + + {% endif %} + | {% endfor %} {% for result in dns %} @@ -170,8 +206,10 @@{{ result.age }} | {{ result.sex }} | {{ result.weightcategory }} | + {% if race.sessiontype == 'race' %}{{ result.boatclass }} | {{ result.boattype }} | + {% endif %}DNS | {% endfor %} @@ -210,8 +248,10 @@
| Name | Team Name | + {% if race.sessiontype == 'race' %}Class | Boat | + {% endif %}Age | Gender | Weight Category | @@ -221,8 +261,10 @@|||
| {{ record.username }} | {{ record.teamname }} | + {% if race.sessiontype == 'race' %}{{ record.boatclass }} | {{ record.boattype }} | + {% endif %}{{ record.age }} | {{ record.sex }} | {{ record.weightcategory }} | @@ -247,6 +289,16 @@ 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. + +