making upload options sticky and adding make private
This commit is contained in:
@@ -228,7 +228,8 @@ def timedeltaconv(x):
|
||||
# Processes painsled CSV file to database
|
||||
def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
|
||||
dosummary=True,title='Workout',
|
||||
notes='',totaldist=0,totaltime=0):
|
||||
notes='',totaldist=0,totaltime=0,
|
||||
makeprivate=False):
|
||||
message = None
|
||||
powerperc = 100*np.array([r.pw_ut2,
|
||||
r.pw_ut1,
|
||||
@@ -313,12 +314,18 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
|
||||
workoutstarttime = row.rowdatetime.strftime('%H:%M:%S')
|
||||
workoutstartdatetime = thetimezone.localize(row.rowdatetime).astimezone(utc)
|
||||
|
||||
if makeprivate:
|
||||
privacy = 'private'
|
||||
else:
|
||||
privacy = 'visible'
|
||||
|
||||
# check for duplicate start times
|
||||
ws = Workout.objects.filter(starttime=workoutstarttime,
|
||||
user=r)
|
||||
if (len(ws) != 0):
|
||||
message = "Warning: This workout probably already exists in the database"
|
||||
|
||||
|
||||
w = Workout(user=r,name=title,date=workoutdate,
|
||||
workouttype=workouttype,
|
||||
duration=duration,distance=totaldist,
|
||||
@@ -326,15 +333,16 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
|
||||
starttime=workoutstarttime,
|
||||
csvfilename=f2,notes=notes,summary=summary,
|
||||
maxhr=maxhr,averagehr=averagehr,
|
||||
startdatetime=workoutstartdatetime)
|
||||
startdatetime=workoutstartdatetime,
|
||||
privacy=privacy)
|
||||
|
||||
|
||||
w.save()
|
||||
|
||||
ts = Team.objects.filter(rower=r)
|
||||
|
||||
for t in ts:
|
||||
w.team.add(t)
|
||||
if privacy == 'visible':
|
||||
ts = Team.objects.filter(rower=r)
|
||||
for t in ts:
|
||||
w.team.add(t)
|
||||
|
||||
# put stroke data in database
|
||||
res = dataprep(row.df,id=w.id,bands=True,
|
||||
@@ -422,6 +430,7 @@ def handle_nonpainsled(f2,fileformat,summary=''):
|
||||
def new_workout_from_file(r,f2,
|
||||
workouttype='rower',
|
||||
title='Workout',
|
||||
makeprivate=False,
|
||||
notes=''):
|
||||
message = None
|
||||
fileformat = get_file_type(f2)
|
||||
@@ -470,6 +479,7 @@ def new_workout_from_file(r,f2,
|
||||
dosummary = (fileformat != 'fit')
|
||||
id,message = save_workout_database(f2,r,
|
||||
workouttype=workouttype,
|
||||
makeprivate=makeprivate,
|
||||
dosummary=dosummary,
|
||||
title=title)
|
||||
|
||||
|
||||
@@ -76,14 +76,15 @@ class UploadOptionsForm(forms.Form):
|
||||
('distanceplot','Distance Plot'),
|
||||
('pieplot','Pie Chart'),
|
||||
)
|
||||
make_plot = forms.BooleanField(initial=False)
|
||||
make_plot = forms.BooleanField(initial=False,required=False)
|
||||
plottype = forms.ChoiceField(required=False,
|
||||
choices=plotchoices,
|
||||
initial='timeplot')
|
||||
upload_to_C2 = forms.BooleanField(initial=False)
|
||||
upload_to_C2 = forms.BooleanField(initial=False,required=False)
|
||||
makeprivate = forms.BooleanField(initial=False,required=False)
|
||||
|
||||
class Meta:
|
||||
fields = ['make_plot','plottype','upload_toc2']
|
||||
fields = ['make_plot','plottype','upload_toc2','makeprivate']
|
||||
|
||||
# This form is used on the Analysis page to add a custom distance/time
|
||||
# trial and predict the pace
|
||||
|
||||
@@ -4181,7 +4181,26 @@ def workout_getc2workout_view(request,c2id):
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# This is the main view for processing uploaded files
|
||||
@login_required()
|
||||
@login_required()
|
||||
def workout_upload_view(request,message="",
|
||||
uploadoptions={
|
||||
'makeprivate':False,
|
||||
'make_plot':False,
|
||||
'upload_to_C2':False,
|
||||
'plottype':'timeplot',
|
||||
}):
|
||||
|
||||
if 'uploadoptions' in request.session:
|
||||
uploadoptions = request.session['uploadoptions']
|
||||
else:
|
||||
request.session['uploadoptions'] = uploadoptions
|
||||
|
||||
|
||||
|
||||
makeprivate = uploadoptions['makeprivate']
|
||||
make_plot = uploadoptions['make_plot']
|
||||
plottype = uploadoptions['plottype']
|
||||
upload_toc2 = uploadoptions['upload_to_C2']
|
||||
|
||||
r = Rower.objects.get(user=request.user)
|
||||
if request.method == 'POST':
|
||||
@@ -4193,10 +4212,22 @@ def workout_upload_view(request,message=""):
|
||||
t = form.cleaned_data['title']
|
||||
workouttype = form.cleaned_data['workouttype']
|
||||
|
||||
notes = form.cleaned_data['notes']
|
||||
make_plot = request.POST.getlist('make_plot')
|
||||
plottype = request.POST['plottype']
|
||||
notes = form.cleaned_data['notes']
|
||||
|
||||
if optionsform.is_valid():
|
||||
make_plot = optionsform.cleaned_data['make_plot']
|
||||
plottype = optionsform.cleaned_data['plottype']
|
||||
upload_to_c2 = optionsform.cleaned_data['upload_to_C2']
|
||||
makeprivate = optionsform.cleaned_data['makeprivate']
|
||||
|
||||
uploadoptions = {
|
||||
'makeprivate':makeprivate,
|
||||
'make_plot':make_plot,
|
||||
'plottype':plottype,
|
||||
'upload_to_C2':upload_to_c2,
|
||||
}
|
||||
|
||||
|
||||
request.session['uploadoptions'] = uploadoptions
|
||||
|
||||
f1 = res[0] # file name
|
||||
@@ -4204,6 +4235,7 @@ def workout_upload_view(request,message=""):
|
||||
|
||||
|
||||
id,message = dataprep.new_workout_from_file(r,f2,
|
||||
workouttype=workouttype,
|
||||
makeprivate=makeprivate,
|
||||
title = t,
|
||||
notes='')
|
||||
@@ -4344,7 +4376,7 @@ def workout_upload_view(request,message=""):
|
||||
|
||||
return response
|
||||
else:
|
||||
form = DocumentsForm()
|
||||
form = DocumentsForm()
|
||||
optionsform = UploadOptionsForm(initial=uploadoptions)
|
||||
return render(request, 'document_form.html',
|
||||
{'form':form,
|
||||
|
||||
Reference in New Issue
Block a user