working submission
This commit is contained in:
@@ -124,7 +124,7 @@ class EmailForm(forms.Form):
|
||||
subject = forms.CharField(max_length=255)
|
||||
message = forms.CharField(widget=forms.Textarea())
|
||||
|
||||
|
||||
|
||||
|
||||
disqualificationreasons = (
|
||||
('noimage','No monitor screenshot or data evidence was included'),
|
||||
@@ -386,7 +386,7 @@ class UploadOptionsForm(forms.Form):
|
||||
makeprivate = forms.BooleanField(initial=False,required=False,
|
||||
label='Make Workout Private')
|
||||
|
||||
submitrace = forms.ModelChoiceField(queryset=VirtualRace.objects.all(),
|
||||
submitrace = forms.ChoiceField(
|
||||
label='Submit as challenge Result',
|
||||
required=False)
|
||||
|
||||
@@ -404,6 +404,7 @@ class UploadOptionsForm(forms.Form):
|
||||
r = Rower.objects.get(user=self.request.user)
|
||||
races = VirtualRace.objects.filter(
|
||||
registration_closure__gt=timezone.now())
|
||||
|
||||
registrations = IndoorVirtualRaceResult.objects.filter(
|
||||
race__in = races,
|
||||
userid = r.id)
|
||||
@@ -413,25 +414,27 @@ class UploadOptionsForm(forms.Form):
|
||||
userid = r.id,
|
||||
)
|
||||
|
||||
raceids = [r.race.id for r in registrations]
|
||||
raceids2 = [r.race.id for r in registrations2]
|
||||
choices1 = [(r.id,str(r)) for r in registrations]
|
||||
choices2 = [(r.id,str(r)) for r in registrations2]
|
||||
choices3 = [(0,'---')]
|
||||
|
||||
raceids = raceids+raceids2
|
||||
choices = choices3+choices1+choices2
|
||||
|
||||
races = VirtualRace.objects.filter(
|
||||
id__in=raceids
|
||||
)
|
||||
if int(raceid) in [r.id for r in races]:
|
||||
therace = VirtualRace.objects.get(id=raceid)
|
||||
if therace.sessiontype == 'race':
|
||||
registrations = VirtualRaceResult.objects.filter(race=therace,userid=r.id)
|
||||
else:
|
||||
registrations = IndoorVirtualRaceResult.objects.filter(race=therace,userid=r.id)
|
||||
|
||||
choices = [(r.id,str(r)) for r in registrations]
|
||||
choices = [(0,'---')]+choices
|
||||
|
||||
if races:
|
||||
self.fields['submitrace'].queryset = races
|
||||
self.fields['submitrace'].choices = choices
|
||||
else:
|
||||
del self.fields['submitrace']
|
||||
|
||||
if int(raceid) in raceids:
|
||||
self.fields['submitrace'].initial = VirtualRace.objects.get(id=raceid)
|
||||
|
||||
|
||||
|
||||
# The form to indicate additional actions to be performed immediately
|
||||
# after a successful upload. This version allows the Team manager to select
|
||||
|
||||
@@ -1343,6 +1343,7 @@ def remove_rower_race(r,race,recordid=None):
|
||||
|
||||
# Low Level functions - to be called by higher level methods
|
||||
def add_workout_indoorrace(ws,race,r,recordid=0):
|
||||
print('aap')
|
||||
result = 0
|
||||
comments = []
|
||||
errors = []
|
||||
@@ -1402,6 +1403,8 @@ def add_workout_indoorrace(ws,race,r,recordid=0):
|
||||
workoutid = ws[0].id
|
||||
)
|
||||
|
||||
print(record,records)
|
||||
|
||||
if not record:
|
||||
errors.append("Couldn't find this entry")
|
||||
return result,comments,errors,0
|
||||
@@ -1471,7 +1474,7 @@ def add_workout_indoorrace(ws,race,r,recordid=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,doregister=False):
|
||||
result = 0
|
||||
comments = []
|
||||
errors = []
|
||||
|
||||
@@ -4909,7 +4909,7 @@ def workout_upload_view(request,
|
||||
notes = form.cleaned_data['notes']
|
||||
offline = form.cleaned_data['offline']
|
||||
|
||||
race = None
|
||||
registrationid = 0
|
||||
if optionsform.is_valid():
|
||||
make_plot = optionsform.cleaned_data['make_plot']
|
||||
plottype = optionsform.cleaned_data['plottype']
|
||||
@@ -4923,9 +4923,9 @@ def workout_upload_view(request,
|
||||
landingpage = optionsform.cleaned_data['landingpage']
|
||||
|
||||
try:
|
||||
race = optionsform.cleaned_data['submitrace']
|
||||
registrationid = optionsform.cleaned_data['submitrace']
|
||||
except KeyError:
|
||||
race = None
|
||||
registrationid = 0
|
||||
|
||||
uploadoptions = {
|
||||
'makeprivate':makeprivate,
|
||||
@@ -5113,17 +5113,60 @@ def workout_upload_view(request,
|
||||
else:
|
||||
messages.error(request,message)
|
||||
|
||||
if race and race_can_submit(r,race):
|
||||
if race.sessiontype == 'indoorrace':
|
||||
records = IndoorVirtualRaceResult.objects.filter(
|
||||
race=race,
|
||||
userid=r.id
|
||||
if int(registrationid) < 0:
|
||||
race = VirtualRace.Objects.get(id=-int(registrationid))
|
||||
if race.sessiontype == 'race':
|
||||
race = registrations[0].race
|
||||
result,comments,errors,jobid = add_workout_race(
|
||||
[w], race,r,
|
||||
)
|
||||
if result:
|
||||
messages.info(
|
||||
request,
|
||||
"We have submitted your workout to the race")
|
||||
|
||||
for c in comments:
|
||||
messages.info(request,c)
|
||||
for er in errors:
|
||||
messages.error(request,er)
|
||||
elif race.sessiontype == 'indoorrace':
|
||||
race = registrations[0].race
|
||||
result,comments,errors,jobid = add_workout_indoorrace(
|
||||
[w],race,r,
|
||||
)
|
||||
|
||||
if records:
|
||||
if result:
|
||||
messages.info(
|
||||
request,
|
||||
"We have submitted your workout to the race")
|
||||
|
||||
for c in comments:
|
||||
messages.info(request,c)
|
||||
for er in errors:
|
||||
messages.error(request,er)
|
||||
|
||||
if int(registrationid)>0:
|
||||
races = VirtualRace.objects.filter(
|
||||
registration_closure__gt=timezone.now()
|
||||
)
|
||||
registrations = IndoorVirtualRaceResult.objects.filter(
|
||||
race__in = races,
|
||||
id=registrationid,
|
||||
userid = r.id,
|
||||
)
|
||||
registrations2 = VirtualRaceResult.objects.filter(
|
||||
race__in = races,
|
||||
id=registrationid,
|
||||
userid=r.id,
|
||||
)
|
||||
|
||||
if int(registrationid) in [r.id for r in registrations]:
|
||||
# indoor race
|
||||
registrations = registrations.filter(id=registrationid)
|
||||
if registrations:
|
||||
race = registrations[0].race
|
||||
result,comments,errors,jobid = add_workout_indoorrace(
|
||||
[w],race,r,recordid=records[0].id
|
||||
[w],race,r,recordid=registrations[0].id
|
||||
)
|
||||
|
||||
if result:
|
||||
@@ -5135,15 +5178,15 @@ def workout_upload_view(request,
|
||||
messages.info(request,c)
|
||||
for er in errors:
|
||||
messages.error(request,er)
|
||||
if race.sessiontype == 'race':
|
||||
records = VirtualRaceResult.objects.filter(
|
||||
race=race,userid=r.id
|
||||
)
|
||||
|
||||
|
||||
if records:
|
||||
if int(registrationid) in [r.id for r in registrations2]:
|
||||
# race
|
||||
registrations = registrations2.filter(id=registrationid)
|
||||
if registrations:
|
||||
race = registrations[0].race
|
||||
result,comments,errors,jobid = add_workout_race(
|
||||
[w], race,r,recordid=records[0].id
|
||||
[w], race,r,recordid=registrations[0].id
|
||||
)
|
||||
if result:
|
||||
messages.info(
|
||||
@@ -5156,6 +5199,7 @@ def workout_upload_view(request,
|
||||
messages.error(request,er)
|
||||
|
||||
|
||||
|
||||
if landingpage != 'workout_upload_view':
|
||||
url = reverse(landingpage,
|
||||
kwargs = {
|
||||
|
||||
Reference in New Issue
Block a user