race submission code in place, failing, littered with debug statements
This commit is contained in:
@@ -36,6 +36,7 @@ import courses
|
||||
import iso8601
|
||||
from iso8601 import ParseError
|
||||
from rowers.tasks import handle_check_race_course
|
||||
from rowers.utils import totaltime_sec_to_string
|
||||
|
||||
def get_indoorraces(workout):
|
||||
races1 = VirtualRace.objects.filter(
|
||||
@@ -777,7 +778,6 @@ def race_can_submit(r,race):
|
||||
else:
|
||||
return False
|
||||
|
||||
print 'pop'
|
||||
return False
|
||||
|
||||
def race_can_resubmit(r,race):
|
||||
@@ -877,6 +877,134 @@ def race_can_withdraw(r,race):
|
||||
|
||||
return True
|
||||
|
||||
def email_submit_race(r,race,workoutid):
|
||||
try:
|
||||
w = Workout.objects.get(id=workoutid)
|
||||
except Workout.DoesNotExist:
|
||||
return 0
|
||||
|
||||
if race.sessionmode == 'time':
|
||||
wduration = timefield_to_seconds_duration(w.duration)
|
||||
delta = wduration - (60.*race.sessionvalue)
|
||||
|
||||
if delta > -2 and delta < 2:
|
||||
w.duration = totaltime_sec_to_string(60.*race.sessionvalue)
|
||||
w.save()
|
||||
|
||||
elif race.sessionmode == 'distance':
|
||||
delta = w.distance - race.sessionvalue
|
||||
|
||||
if delta > -5 and delta < 5:
|
||||
w.distance = race.sessionvalue
|
||||
w.save()
|
||||
|
||||
|
||||
if race_can_register(r,race):
|
||||
teamname = ''
|
||||
weightcategory = w.weightcategory
|
||||
sex = r.sex
|
||||
if sex == 'not specified':
|
||||
sex = 'male'
|
||||
|
||||
if not r.birthdate:
|
||||
return 0
|
||||
|
||||
age = calculate_age(r.birthdate)
|
||||
|
||||
adaptiveclass = r.adaptiveclass
|
||||
boatclass = w.workouttype
|
||||
|
||||
record = IndoorVirtualRaceResult(
|
||||
userid = r.id,
|
||||
teamname=teamname,
|
||||
race=race,
|
||||
username = u'{f} {l}'.format(
|
||||
f = r.user.first_name,
|
||||
l = r.user.last_name
|
||||
),
|
||||
weightcategory=weightcategory,
|
||||
adaptiveclass=adaptiveclass,
|
||||
duration=dt.time(0,0),
|
||||
boatclass=boatclass,
|
||||
coursecompleted=False,
|
||||
sex=sex,
|
||||
age=age
|
||||
)
|
||||
|
||||
record.save()
|
||||
|
||||
result = add_rower_race(r,race)
|
||||
|
||||
otherrecords = IndoorVirtualRaceResult.objects.filter(
|
||||
race = race).exclude(userid = r.id)
|
||||
|
||||
for otherrecord in otherrecords:
|
||||
otheruser = Rower.objects.get(id=otherrecord.userid)
|
||||
othername = otheruser.user.first_name+' '+otheruser.user.last_name
|
||||
registeredname = r.user.first_name+' '+r.user.last_name
|
||||
if otherrecord.emailnotifications:
|
||||
job = myqueue(
|
||||
queue,
|
||||
handle_sendemail_raceregistration,
|
||||
otheruser.user.email, othername,
|
||||
registeredname,
|
||||
race.name,
|
||||
race.id
|
||||
)
|
||||
|
||||
|
||||
if race_can_submit(r,race):
|
||||
records = IndoorVirtualRaceResult.objects.filter(
|
||||
userid = r.id,
|
||||
race=race
|
||||
)
|
||||
|
||||
if not records:
|
||||
print 'jet'
|
||||
return 0
|
||||
|
||||
record = records[0]
|
||||
|
||||
workouts = Workout.objects.filter(id=w.id)
|
||||
print workouts
|
||||
print record.id
|
||||
print 'aap'
|
||||
|
||||
result,comments,errors,jobid = add_workout_indoorrace(
|
||||
workouts,race,r,recordid=record.id
|
||||
)
|
||||
|
||||
print result,'noot'
|
||||
|
||||
if result:
|
||||
otherrecords = resultobj.objects.filter(
|
||||
race = race).exclude(userid = r.id)
|
||||
|
||||
for otherrecord in otherrecords:
|
||||
otheruser = Rower.objects.get(id=otherrecord.userid)
|
||||
othername = otheruser.user.first_name+' '+otheruser.user.last_name
|
||||
registeredname = r.user.first_name+' '+r.user.last_name
|
||||
if otherrecord.emailnotifications:
|
||||
job = myqueue(
|
||||
queue,
|
||||
handle_sendemail_racesubmission,
|
||||
otheruser.user.email, othername,
|
||||
registeredname,
|
||||
race.name,
|
||||
race.id
|
||||
)
|
||||
|
||||
return 1
|
||||
else:
|
||||
for error in errors:
|
||||
print error
|
||||
print 'fail'
|
||||
else:
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
def race_can_register(r,race):
|
||||
if race.sessiontype == 'race':
|
||||
recordobj = VirtualRaceResult
|
||||
|
||||
Reference in New Issue
Block a user