Private
Public Access
1
0

replaced len with count() on a few queries

This commit is contained in:
Sander Roosendaal
2019-10-31 18:32:58 +01:00
parent 9d6eabca19
commit df80860ed1
4 changed files with 248 additions and 253 deletions

View File

@@ -13,7 +13,7 @@ def create_alert(manager, rower, measured,period=7, emailalert=True,
if manager.rower != rower: if manager.rower != rower:
if rower not in coach_getcoachees(manager.rower): if rower not in coach_getcoachees(manager.rower):
return 0,'You are not allowed to create this alert' return 0,'You are not allowed to create this alert'
m = Condition( m = Condition(
metric = measured['metric'], metric = measured['metric'],
value1 = measured['value1'], value1 = measured['value1'],
@@ -22,7 +22,7 @@ def create_alert(manager, rower, measured,period=7, emailalert=True,
) )
m.save() m.save()
alert = Alert(name=name, alert = Alert(name=name,
manager=manager, manager=manager,
rower=rower, rower=rower,
@@ -46,7 +46,7 @@ def create_alert(manager, rower, measured,period=7, emailalert=True,
value2 = f['value2'], value2 = f['value2'],
condition = f['condition'] condition = f['condition']
) )
m.save() m.save()
alert.filter.add(m) alert.filter.add(m)
@@ -79,7 +79,7 @@ def alert_add_filters(alert,filters):
m.save() m.save()
alert.filter.add(m) alert.filter.add(m)
return 1 return 1
# get alert stats # get alert stats
@@ -104,7 +104,7 @@ def alert_get_stats(alert,nperiod=0):
if df.empty: if df.empty:
return { return {
'workouts':len(workouts), 'workouts':workouts.count(),
'startdate':startdate, 'startdate':startdate,
'enddate':enddate, 'enddate':enddate,
'nr_strokes':0, 'nr_strokes':0,
@@ -139,7 +139,7 @@ def alert_get_stats(alert,nperiod=0):
df.dropna(inplace=True,axis=0) df.dropna(inplace=True,axis=0)
else: else:
return { return {
'workouts':len(workouts), 'workouts':workouts.count(),
'startdate':startdate, 'startdate':startdate,
'enddate':enddate, 'enddate':enddate,
'nr_strokes':0, 'nr_strokes':0,
@@ -150,11 +150,11 @@ def alert_get_stats(alert,nperiod=0):
'median_q': 0, 'median_q': 0,
'standard_dev': 0, 'standard_dev': 0,
} }
# count strokes # count strokes
nr_strokes = len(df) nr_strokes = len(df)
# count qualifying # count qualifying
if alert.measured.condition == '>': if alert.measured.condition == '>':
@@ -164,7 +164,7 @@ def alert_get_stats(alert,nperiod=0):
mask = df[alert.measured.metric] < alert.measured.value1 mask = df[alert.measured.metric] < alert.measured.value1
df2 = df[mask].copy() df2 = df[mask].copy()
elif alert.measured.condition == 'between': elif alert.measured.condition == 'between':
mask = df[alert.measured.metric] > alert.measured.value1 mask = df[alert.measured.metric] > alert.measured.value1
mask2 = df[alert.measured.metric] < alert.measured.value2 mask2 = df[alert.measured.metric] < alert.measured.value2
df2 = df[mask & mask2].copy() df2 = df[mask & mask2].copy()
else: else:
@@ -181,9 +181,9 @@ def alert_get_stats(alert,nperiod=0):
median_q = df2[alert.measured.metric].median() median_q = df2[alert.measured.metric].median()
median = df[alert.measured.metric].median() median = df[alert.measured.metric].median()
std = df[alert.measured.metric].std() std = df[alert.measured.metric].std()
return { return {
'workouts':len(workouts), 'workouts':workouts.count(),
'startdate':startdate, 'startdate':startdate,
'enddate':enddate, 'enddate':enddate,
'nr_strokes':nr_strokes, 'nr_strokes':nr_strokes,

View File

@@ -364,7 +364,7 @@ class Team(models.Model):
if manager.rower.rowerplan in ['plan','pro']: if manager.rower.rowerplan in ['plan','pro']:
otherteams = Team.objects.filter(manager=manager) otherteams = Team.objects.filter(manager=manager)
if len(otherteams) >= 1: if otherteams.count() >= 1:
raise ValidationError( raise ValidationError(
"Pro and Self-Coach users cannot have more than one team" "Pro and Self-Coach users cannot have more than one team"
) )
@@ -569,7 +569,7 @@ def course_length(course):
if not polygons: if not polygons:
return 0 return 0
for i in range(len(polygons)-1): for i in range(polygons.count()-1):
latitude1,longitude1 = polygon_coord_center(polygons[i]) latitude1,longitude1 = polygon_coord_center(polygons[i])
latitude2,longitude2 = polygon_coord_center(polygons[i+1]) latitude2,longitude2 = polygon_coord_center(polygons[i+1])
@@ -656,7 +656,7 @@ class CoachingGroup(models.Model):
def __len__(self): def __len__(self):
rs = Rower.objects.filter(coachinggroups__in=[self]) rs = Rower.objects.filter(coachinggroups__in=[self])
return len(rs) return rs.count()
# Extension of User with rowing specific data # Extension of User with rowing specific data
@python_2_unicode_compatible @python_2_unicode_compatible
@@ -3133,7 +3133,7 @@ def auto_delete_image_on_delete(sender,instance, **kwargs):
if instance.filename: if instance.filename:
if os.path.isfile(instance.filename): if os.path.isfile(instance.filename):
others = GraphImage.objects.filter(filename=instance.filename) others = GraphImage.objects.filter(filename=instance.filename)
if len(others) == 0: if others.count() == 0:
os.remove(instance.filename) os.remove(instance.filename)
else: else:
print("couldn't find the file "+instance.filename) print("couldn't find the file "+instance.filename)

View File

@@ -62,7 +62,7 @@ def checkscores(r,macrocycles):
m.plantrimp = 0 m.plantrimp = 0
m.actualtrimp = 0 m.actualtrimp = 0
mesocycles = TrainingMesoCycle.objects.filter( mesocycles = TrainingMesoCycle.objects.filter(
plan=m, plan=m,
type='userdefined').order_by("startdate") type='userdefined').order_by("startdate")
@@ -76,19 +76,19 @@ def checkscores(r,macrocycles):
me.actualrscore = 0 me.actualrscore = 0
me.plantrimp = 0 me.plantrimp = 0
me.actualtrimp = 0 me.actualtrimp = 0
microcycles = TrainingMicroCycle.objects.filter( microcycles = TrainingMicroCycle.objects.filter(
plan=me, plan=me,
type='userdefined').order_by("startdate") type='userdefined').order_by("startdate")
for mm in microcycles: for mm in microcycles:
sps = get_sessions(r,startdate=mm.startdate,enddate=mm.enddate) sps = get_sessions(r,startdate=mm.startdate,enddate=mm.enddate)
# sps = PlannedSession.objects.filter( # sps = PlannedSession.objects.filter(
# rower = r, # rower = r,
# startdate__lte=mm.enddate, # startdate__lte=mm.enddate,
# enddate__gte=mm.startdate) # enddate__gte=mm.startdate)
mm.plantime = 0 mm.plantime = 0
mm.actualtime = 0 mm.actualtime = 0
@@ -139,11 +139,11 @@ def checkscores(r,macrocycles):
m.plantrimp += me.plantrimp m.plantrimp += me.plantrimp
m.actualtrimp += me.actualtrimp m.actualtrimp += me.actualtrimp
if m.type == 'userdefined': if m.type == 'userdefined':
m.save() m.save()
def get_execution_report(rower,startdate,enddate,plan=None): def get_execution_report(rower,startdate,enddate,plan=None):
if plan: if plan:
@@ -188,7 +188,7 @@ def get_execution_report(rower,startdate,enddate,plan=None):
startdates = [] startdates = []
planned = [] planned = []
executed = [] executed = []
for mm in micros: for mm in micros:
plannedscore = 0 plannedscore = 0
actualscore = 0 actualscore = 0
@@ -219,7 +219,7 @@ def get_execution_report(rower,startdate,enddate,plan=None):
plannedscore += 60. plannedscore += 60.
elif ps.sessionmode == 'TRIMP': elif ps.sessionmode == 'TRIMP':
plannedscore += ps.sessionvalue/2. plannedscore += ps.sessionvalue/2.
for w in ws: for w in ws:
if w.rscore != 0: if w.rscore != 0:
if ratio > 0: if ratio > 0:
@@ -234,19 +234,19 @@ def get_execution_report(rower,startdate,enddate,plan=None):
actualscore += w.hrtss actualscore += w.hrtss
else: else:
plannedscore += 60 plannedscore += 60
actualscore += 0 actualscore += 0
else: else:
minutes = w.duration.hour*60+w.duration.minute minutes = w.duration.hour*60+w.duration.minute
if ratio > 0: if ratio > 0:
plannedscore += minutes/ratio plannedscore += minutes/ratio
else: else:
plannedscore += 60 plannedscore += 60
actualscore += minutes actualscore += minutes
actualscore = int(actualscore) actualscore = int(actualscore)
plannedscore = int(plannedscore) plannedscore = int(plannedscore)
startdates += [mm.startdate] startdates += [mm.startdate]
planned += [plannedscore] planned += [plannedscore]
executed += [actualscore] executed += [actualscore]
@@ -272,14 +272,14 @@ def get_indoorraces(workout):
if workout.duration.second == 0 and workout.duration.microsecond == 0: if workout.duration.second == 0 and workout.duration.microsecond == 0:
duration = 60*workout.duration.hour+workout.duration.minute duration = 60*workout.duration.hour+workout.duration.minute
races2 = VirtualRace.objects.filter( races2 = VirtualRace.objects.filter(
sessiontype='indoorrace', sessiontype='indoorrace',
startdate__lte=workout.date, startdate__lte=workout.date,
enddate__gte=workout.date, enddate__gte=workout.date,
sessionmode='time', sessionmode='time',
sessionvalue=duration) sessionvalue=duration)
races = races1 | races2 races = races1 | races2
else: else:
races = races1 races = races1
@@ -290,13 +290,13 @@ def get_indoorraces(workout):
userid=workout.user.id) userid=workout.user.id)
races = [r.race for r in registrations] races = [r.race for r in registrations]
return races return races
def get_todays_micro(plan,thedate=date.today()): def get_todays_micro(plan,thedate=date.today()):
thismicro = None thismicro = None
thismacro = TrainingMacroCycle.objects.filter( thismacro = TrainingMacroCycle.objects.filter(
plan=plan, plan=plan,
startdate__lte = thedate, startdate__lte = thedate,
@@ -334,7 +334,7 @@ def add_workouts_plannedsession(ws,ps,r):
errors.append('For tests and training sessions, selected workouts must all be done on the same date') errors.append('For tests and training sessions, selected workouts must all be done on the same date')
return result,comments,errors return result,comments,errors
if len(ws)>1 and ps.sessiontype == 'test': if ws.count()>1 and ps.sessiontype == 'test':
errors.append('For tests, you can only attach one workout') errors.append('For tests, you can only attach one workout')
return result,comments,errors return result,comments,errors
@@ -438,7 +438,7 @@ def get_session_metrics(ps):
ws = Workout.objects.filter(user=r,plannedsession=ps).order_by("date") ws = Workout.objects.filter(user=r,plannedsession=ps).order_by("date")
if len(ws) != 0: if ws.count() != 0:
for w in ws: for w in ws:
distancev += w.distance distancev += w.distance
durationv += timefield_to_seconds_duration(w.duration) durationv += timefield_to_seconds_duration(w.duration)
@@ -493,7 +493,7 @@ cratiocolors = {
def is_session_complete_ws(ws,ps): def is_session_complete_ws(ws,ps):
ws = ws.order_by("date") ws = ws.order_by("date")
if len(ws)==0: if ws.count()==0:
today = date.today() today = date.today()
if today > ps.enddate: if today > ps.enddate:
verdict = 'missed' verdict = 'missed'
@@ -519,7 +519,7 @@ def is_session_complete_ws(ws,ps):
'way over target': 1.5 'way over target': 1.5
} }
if ps.criterium == 'none': if ps.criterium == 'none':
if ps.sessiontype == 'session': if ps.sessiontype == 'session':
cratiomin = 0.8 cratiomin = 0.8
@@ -549,7 +549,7 @@ def is_session_complete_ws(ws,ps):
elif rscore == 0: elif rscore == 0:
trimp,hrtss = dataprep.workout_trimp(w) trimp,hrtss = dataprep.workout_trimp(w)
score += hrtss score += hrtss
if not completiondate and score>=cratiomin*value: if not completiondate and score>=cratiomin*value:
completiondate = w.date completiondate = w.date
@@ -646,7 +646,7 @@ def is_session_complete_ws(ws,ps):
mode='coursetest') mode='coursetest')
return (0,'not done',None) return (0,'not done',None)
else: else:
if not completiondate: if not completiondate:
@@ -657,7 +657,7 @@ def is_session_complete_ws(ws,ps):
def is_session_complete(r,ps): def is_session_complete(r,ps):
verdict = 'not done' verdict = 'not done'
if r not in ps.rower.all(): if r not in ps.rower.all():
return 0,'not assigned',None return 0,'not assigned',None
@@ -686,7 +686,7 @@ def add_rower_session(r,ps):
elif ps.manager.rower == r and r.rowerplan != 'freecoach': elif ps.manager.rower == r and r.rowerplan != 'freecoach':
ps.rower.add(r) ps.rower.add(r)
ps.save() ps.save()
return 0 return 0
def remove_team_session(t,ps): def remove_team_session(t,ps):
@@ -722,9 +722,9 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
except ValueError: except ValueError:
startdate = parser.parse(startdatestring,fuzzy=True) startdate = parser.parse(startdatestring,fuzzy=True)
enddate = parser.parse(enddatestring, fuzzy=True) enddate = parser.parse(enddatestring, fuzzy=True)
return startdate,enddate return startdate,enddate
daterangetester = re.compile('^(\d+-\d+-\d+)\/(\d+-\d+-\d+)') daterangetester = re.compile('^(\d+-\d+-\d+)\/(\d+-\d+-\d+)')
if timeperiod=='today': if timeperiod=='today':
@@ -770,7 +770,7 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
elif timeperiod=='lastyear': elif timeperiod=='lastyear':
today = date.today() today = date.today()
startdate = today-timezone.timedelta(days=365) startdate = today-timezone.timedelta(days=365)
enddate = today+timezone.timedelta(days=1) enddate = today+timezone.timedelta(days=1)
elif daterangetester.match(timeperiod): elif daterangetester.match(timeperiod):
tstartdatestring = daterangetester.match(timeperiod).group(1) tstartdatestring = daterangetester.match(timeperiod).group(1)
tenddatestring = daterangetester.match(timeperiod).group(2) tenddatestring = daterangetester.match(timeperiod).group(2)
@@ -783,18 +783,18 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
startdate = startdate2 startdate = startdate2
except ValueError: except ValueError:
startdate = date.today() startdate = date.today()
enddate = date.today() enddate = date.today()
else: else:
startdate = date.today() startdate = date.today()
enddate = date.today() enddate = date.today()
if startdatestring != '': if startdatestring != '':
try: try:
startdate = iso8601.parse_date(startdatestring) startdate = iso8601.parse_date(startdatestring)
except ParseError: except ParseError:
pass pass
if enddatestring != '': if enddatestring != '':
try: try:
enddate = iso8601.parse_date(enddatestring) enddate = iso8601.parse_date(enddatestring)
@@ -834,7 +834,7 @@ def get_sessions(r,startdate=date.today(),
rower__in=[r], rower__in=[r],
startdate__lte=enddate, startdate__lte=enddate,
enddate__gte=startdate, enddate__gte=startdate,
is_template=False, is_template=False,
).order_by("preferreddate","startdate","enddate").exclude( ).order_by("preferreddate","startdate","enddate").exclude(
sessiontype='race').exclude(sessiontype='indoorrace') sessiontype='race').exclude(sessiontype='indoorrace')
@@ -871,14 +871,14 @@ def update_indoorvirtualrace(ps,cd):
value.replace("\r\n", "&#10"); value.replace("\r\n", "&#10");
value.replace("\n", "&#10"); value.replace("\n", "&#10");
setattr(ps, attr, value) setattr(ps, attr, value)
timezone_str = cd['timezone'] timezone_str = cd['timezone']
# correct times # correct times
startdatetime = datetime.combine(cd['startdate'],cd['start_time']) startdatetime = datetime.combine(cd['startdate'],cd['start_time'])
enddatetime = datetime.combine(cd['enddate'],cd['end_time']) enddatetime = datetime.combine(cd['enddate'],cd['end_time'])
startdatetime = pytz.timezone(timezone_str).localize( startdatetime = pytz.timezone(timezone_str).localize(
startdatetime startdatetime
) )
@@ -910,7 +910,7 @@ def update_indoorvirtualrace(ps,cd):
ps.registration_closure = registration_closure ps.registration_closure = registration_closure
ps.timezone = timezone_str ps.timezone = timezone_str
ps.save() ps.save()
return 1,'Virtual Race Updated' return 1,'Virtual Race Updated'
@@ -924,14 +924,14 @@ def update_virtualrace(ps,cd):
setattr(ps, attr, value) setattr(ps, attr, value)
# correct times # correct times
course = cd['course'] course = cd['course']
geocourse = GeoCourse.objects.get(id= course.id) geocourse = GeoCourse.objects.get(id= course.id)
timezone_str = get_course_timezone(geocourse) timezone_str = get_course_timezone(geocourse)
startdatetime = datetime.combine(cd['startdate'],cd['start_time']) startdatetime = datetime.combine(cd['startdate'],cd['start_time'])
enddatetime = datetime.combine(cd['enddate'],cd['end_time']) enddatetime = datetime.combine(cd['enddate'],cd['end_time'])
startdatetime = pytz.timezone(timezone_str).localize( startdatetime = pytz.timezone(timezone_str).localize(
startdatetime startdatetime
) )
@@ -963,7 +963,7 @@ def update_virtualrace(ps,cd):
ps.registration_closure = registration_closure ps.registration_closure = registration_closure
ps.timezone = timezone_str ps.timezone = timezone_str
ps.save() ps.save()
return 1,'Virtual Race Updated' return 1,'Virtual Race Updated'
@@ -977,12 +977,12 @@ def race_rower_status(r,race):
resultobj = VirtualRaceResult resultobj = VirtualRaceResult
else: else:
resultobj = IndoorVirtualRaceResult resultobj = IndoorVirtualRaceResult
vs = resultobj.objects.filter(userid=r.id,race=race) vs = resultobj.objects.filter(userid=r.id,race=race)
if vs: if vs:
has_registered = True has_registered = True
is_complete = vs[0].coursecompleted is_complete = vs[0].coursecompleted
return is_complete,has_registered return is_complete,has_registered
def race_can_edit(r,race): def race_can_edit(r,race):
@@ -999,7 +999,7 @@ def race_can_edit(r,race):
return True return True
else: else:
return False return False
return False return False
@@ -1058,7 +1058,7 @@ def race_can_adddiscipline(r,race):
if race.sessiontype != 'race': if race.sessiontype != 'race':
return False return False
records = VirtualRaceResult.objects.filter( records = VirtualRaceResult.objects.filter(
userid=r.id, userid=r.id,
race=race) race=race)
@@ -1066,7 +1066,7 @@ def race_can_adddiscipline(r,race):
if not records: if not records:
return False return False
start_time = race.start_time start_time = race.start_time
start_date = race.startdate start_date = race.startdate
startdatetime = datetime.combine(start_date,start_time) startdatetime = datetime.combine(start_date,start_time)
@@ -1086,24 +1086,24 @@ def race_can_adddiscipline(r,race):
return False return False
return False return False
def race_can_withdraw(r,race): def race_can_withdraw(r,race):
if race.sessiontype == 'race': if race.sessiontype == 'race':
recordobj = VirtualRaceResult recordobj = VirtualRaceResult
else: else:
recordobj = IndoorVirtualRaceResult recordobj = IndoorVirtualRaceResult
records = recordobj.objects.filter( records = recordobj.objects.filter(
userid=r.id, userid=r.id,
race=race race=race
) )
if not records: if not records:
return False return False
start_time = race.start_time start_time = race.start_time
start_date = race.startdate start_date = race.startdate
startdatetime = datetime.combine(start_date,start_time) startdatetime = datetime.combine(start_date,start_time)
@@ -1114,7 +1114,7 @@ def race_can_withdraw(r,race):
registration_closure = race.registration_closure registration_closure = race.registration_closure
if registration_closure is None or registration_closure == '': if registration_closure is None or registration_closure == '':
registration_closure = startdatetime registration_closure = startdatetime
if timezone.now() > registration_closure: if timezone.now() > registration_closure:
return False return False
elif timezone.now() > startdatetime: elif timezone.now() > startdatetime:
@@ -1145,7 +1145,7 @@ def email_submit_race(r,race,workoutid):
w.distance = race.sessionvalue w.distance = race.sessionvalue
w.save() w.save()
if race_can_register(r,race): if race_can_register(r,race):
teamname = '' teamname = ''
weightcategory = w.weightcategory weightcategory = w.weightcategory
@@ -1213,16 +1213,16 @@ def email_submit_race(r,race,workoutid):
record = records[0] record = records[0]
workouts = Workout.objects.filter(id=w.id) workouts = Workout.objects.filter(id=w.id)
result,comments,errors,jobid = add_workout_indoorrace( result,comments,errors,jobid = add_workout_indoorrace(
workouts,race,r,recordid=record.id workouts,race,r,recordid=record.id
) )
if result: if result:
otherrecords = IndoorVirtualRaceResult.objects.filter( otherrecords = IndoorVirtualRaceResult.objects.filter(
race = race) race = race)
for otherrecord in otherrecords: for otherrecord in otherrecords:
otheruser = Rower.objects.get(id=otherrecord.userid) otheruser = Rower.objects.get(id=otherrecord.userid)
othername = otheruser.user.first_name+' '+otheruser.user.last_name othername = otheruser.user.first_name+' '+otheruser.user.last_name
@@ -1241,18 +1241,18 @@ def email_submit_race(r,race,workoutid):
else: else:
return 0 return 0
else: else:
return 0 return 0
return 0 return 0
def race_can_register(r,race): def race_can_register(r,race):
if race.sessiontype == 'race': if race.sessiontype == 'race':
recordobj = VirtualRaceResult recordobj = VirtualRaceResult
else: else:
recordobj = IndoorVirtualRaceResult recordobj = IndoorVirtualRaceResult
records = recordobj.objects.filter( records = recordobj.objects.filter(
userid=r.id, userid=r.id,
race=race) race=race)
@@ -1330,7 +1330,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
errors.append('For tests and training sessions, selected workouts must all be done on the same date') errors.append('For tests and training sessions, selected workouts must all be done on the same date')
return result,comments,errors,0 return result,comments,errors,0
if len(ws)>1 and race.sessiontype == 'test': if ws.count()>1 and race.sessiontype == 'test':
errors.append('For tests, you can only attach one workout') errors.append('For tests, you can only attach one workout')
return result,comments,errors,0 return result,comments,errors,0
@@ -1343,7 +1343,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
errors.append('For tests, you can only attach one workout') errors.append('For tests, you can only attach one workout')
return result,comments,errors,0 return result,comments,errors,0
username = r.user.first_name+' '+r.user.last_name username = r.user.first_name+' '+r.user.last_name
if r.birthdate: if r.birthdate:
@@ -1388,10 +1388,10 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
if ws[0].workouttype != record.boatclass: if ws[0].workouttype != record.boatclass:
errors.append('Your workout boat class is different than on your race registration') errors.append('Your workout boat class is different than on your race registration')
return 0,comments,errors,0 return 0,comments,errors,0
if ws[0].workouttype not in mytypes.otetypes: if ws[0].workouttype not in mytypes.otetypes:
errors.append('You must submit a indoor rowing workout') errors.append('You must submit a indoor rowing workout')
return 0,comments, errors, 0 return 0,comments, errors, 0
if ws[0].weightcategory != record.weightcategory: if ws[0].weightcategory != record.weightcategory:
errors.append('Your workout weight category did not match the weight category you registered') errors.append('Your workout weight category did not match the weight category you registered')
@@ -1416,7 +1416,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
otherrecord.workoutid = None otherrecord.workoutid = None
otherrecord.coursecompleted = False otherrecord.coursecompleted = False
otherrecord.save() otherrecord.save()
record.coursecompleted = True record.coursecompleted = True
record.workoutid = ws[0].id record.workoutid = ws[0].id
@@ -1424,15 +1424,15 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
ws[0].privacy = 'visible' ws[0].privacy = 'visible'
ws[0].save() ws[0].save()
comments.append('Workouts submitted to virtual events have to be public. We have changed the workout to a public workout.') comments.append('Workouts submitted to virtual events have to be public. We have changed the workout to a public workout.')
record.save() record.save()
add_workouts_plannedsession(ws,race,r) add_workouts_plannedsession(ws,race,r)
return result,comments,errors,0 return result,comments,errors,0
def add_workout_race(ws,race,r,splitsecond=0,recordid=0): def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
result = 0 result = 0
comments = [] comments = []
@@ -1458,7 +1458,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
errors.append('For tests and training sessions, selected workouts must all be done on the same date') errors.append('For tests and training sessions, selected workouts must all be done on the same date')
return result,comments,errors,0 return result,comments,errors,0
if len(ws)>1 and race.sessiontype == 'test': if ws.count()>1 and race.sessiontype == 'test':
errors.append('For tests, you can only attach one workout') errors.append('For tests, you can only attach one workout')
return result,comments,errors,0 return result,comments,errors,0
@@ -1471,7 +1471,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
errors.append('For tests, you can only attach one workout') errors.append('For tests, you can only attach one workout')
return result,comments,errors,0 return result,comments,errors,0
username = r.user.first_name+' '+r.user.last_name username = r.user.first_name+' '+r.user.last_name
if r.birthdate: if r.birthdate:
@@ -1498,11 +1498,11 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
if ws[0].workouttype not in mytypes.otwtypes: if ws[0].workouttype not in mytypes.otwtypes:
errors.append('You have to submit a rowing on water workout') errors.append('You have to submit a rowing on water workout')
return 0,comments,errors,0 return 0,comments,errors,0
if ws[0].workouttype != record.boatclass: if ws[0].workouttype != record.boatclass:
errors.append('Your workout boat class is different than on your race registration') errors.append('Your workout boat class is different than on your race registration')
return 0,comments,errors,0 return 0,comments,errors,0
if ws[0].boattype != record.boattype: if ws[0].boattype != record.boattype:
errors.append('Your workout boat type did not match the boat type you registered') errors.append('Your workout boat type did not match the boat type you registered')
return 0,comments,errors,0 return 0,comments,errors,0
@@ -1530,7 +1530,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
otherrecord.workoutid = None otherrecord.workoutid = None
otherrecord.coursecompleted = False otherrecord.coursecompleted = False
otherrecord.save() otherrecord.save()
if ws[0].privacy == 'private': if ws[0].privacy == 'private':
ws[0].privacy = 'visible' ws[0].privacy = 'visible'
ws[0].save() ws[0].save()
@@ -1538,10 +1538,10 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0):
job = myqueue(queue,handle_check_race_course,ws[0].csvfilename, job = myqueue(queue,handle_check_race_course,ws[0].csvfilename,
ws[0].id,race.course.id,record.id,splitsecond=splitsecond) ws[0].id,race.course.id,record.id,splitsecond=splitsecond)
add_workouts_plannedsession(ws,race,r) add_workouts_plannedsession(ws,race,r)
return result,comments,errors,job.id return result,comments,errors,job.id
def delete_race_result(workout,race): def delete_race_result(workout,race):
@@ -1549,5 +1549,3 @@ def delete_race_result(workout,race):
for r in results: for r in results:
r.workoutid = None r.workoutid = None
r.save() r.save()

File diff suppressed because it is too large Load Diff