Private
Public Access
1
0

making upload options sticky and adding make private

This commit is contained in:
Sander Roosendaal
2017-02-15 16:16:02 +01:00
parent 154619a0dc
commit 5deaa194f0
3 changed files with 57 additions and 14 deletions

View File

@@ -228,7 +228,8 @@ def timedeltaconv(x):
# Processes painsled CSV file to database # Processes painsled CSV file to database
def save_workout_database(f2,r,dosmooth=True,workouttype='rower', def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
dosummary=True,title='Workout', dosummary=True,title='Workout',
notes='',totaldist=0,totaltime=0): notes='',totaldist=0,totaltime=0,
makeprivate=False):
message = None message = None
powerperc = 100*np.array([r.pw_ut2, powerperc = 100*np.array([r.pw_ut2,
r.pw_ut1, r.pw_ut1,
@@ -313,12 +314,18 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
workoutstarttime = row.rowdatetime.strftime('%H:%M:%S') workoutstarttime = row.rowdatetime.strftime('%H:%M:%S')
workoutstartdatetime = thetimezone.localize(row.rowdatetime).astimezone(utc) workoutstartdatetime = thetimezone.localize(row.rowdatetime).astimezone(utc)
if makeprivate:
privacy = 'private'
else:
privacy = 'visible'
# check for duplicate start times # check for duplicate start times
ws = Workout.objects.filter(starttime=workoutstarttime, ws = Workout.objects.filter(starttime=workoutstarttime,
user=r) user=r)
if (len(ws) != 0): if (len(ws) != 0):
message = "Warning: This workout probably already exists in the database" message = "Warning: This workout probably already exists in the database"
w = Workout(user=r,name=title,date=workoutdate, w = Workout(user=r,name=title,date=workoutdate,
workouttype=workouttype, workouttype=workouttype,
duration=duration,distance=totaldist, duration=duration,distance=totaldist,
@@ -326,15 +333,16 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower',
starttime=workoutstarttime, starttime=workoutstarttime,
csvfilename=f2,notes=notes,summary=summary, csvfilename=f2,notes=notes,summary=summary,
maxhr=maxhr,averagehr=averagehr, maxhr=maxhr,averagehr=averagehr,
startdatetime=workoutstartdatetime) startdatetime=workoutstartdatetime,
privacy=privacy)
w.save() w.save()
ts = Team.objects.filter(rower=r) if privacy == 'visible':
ts = Team.objects.filter(rower=r)
for t in ts: for t in ts:
w.team.add(t) w.team.add(t)
# put stroke data in database # put stroke data in database
res = dataprep(row.df,id=w.id,bands=True, 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, def new_workout_from_file(r,f2,
workouttype='rower', workouttype='rower',
title='Workout', title='Workout',
makeprivate=False,
notes=''): notes=''):
message = None message = None
fileformat = get_file_type(f2) fileformat = get_file_type(f2)
@@ -470,6 +479,7 @@ def new_workout_from_file(r,f2,
dosummary = (fileformat != 'fit') dosummary = (fileformat != 'fit')
id,message = save_workout_database(f2,r, id,message = save_workout_database(f2,r,
workouttype=workouttype, workouttype=workouttype,
makeprivate=makeprivate,
dosummary=dosummary, dosummary=dosummary,
title=title) title=title)

View File

@@ -76,14 +76,15 @@ class UploadOptionsForm(forms.Form):
('distanceplot','Distance Plot'), ('distanceplot','Distance Plot'),
('pieplot','Pie Chart'), ('pieplot','Pie Chart'),
) )
make_plot = forms.BooleanField(initial=False) make_plot = forms.BooleanField(initial=False,required=False)
plottype = forms.ChoiceField(required=False, plottype = forms.ChoiceField(required=False,
choices=plotchoices, choices=plotchoices,
initial='timeplot') 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: 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 # This form is used on the Analysis page to add a custom distance/time
# trial and predict the pace # trial and predict the pace

View File

@@ -4181,7 +4181,26 @@ def workout_getc2workout_view(request,c2id):
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
# This is the main view for processing uploaded files # 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) r = Rower.objects.get(user=request.user)
if request.method == 'POST': if request.method == 'POST':
@@ -4193,10 +4212,22 @@ def workout_upload_view(request,message=""):
t = form.cleaned_data['title'] t = form.cleaned_data['title']
workouttype = form.cleaned_data['workouttype'] 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'] 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 request.session['uploadoptions'] = uploadoptions
f1 = res[0] # file name f1 = res[0] # file name
@@ -4204,6 +4235,7 @@ def workout_upload_view(request,message=""):
id,message = dataprep.new_workout_from_file(r,f2, id,message = dataprep.new_workout_from_file(r,f2,
workouttype=workouttype,
makeprivate=makeprivate, makeprivate=makeprivate,
title = t, title = t,
notes='') notes='')
@@ -4344,7 +4376,7 @@ def workout_upload_view(request,message=""):
return response return response
else: else:
form = DocumentsForm() form = DocumentsForm()
optionsform = UploadOptionsForm(initial=uploadoptions) optionsform = UploadOptionsForm(initial=uploadoptions)
return render(request, 'document_form.html', return render(request, 'document_form.html',
{'form':form, {'form':form,