simple function to upload workouts to user
This commit is contained in:
@@ -4384,6 +4384,99 @@ def workout_toggle_ranking(request,id=0):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def workout_add(request):
|
||||||
|
if request.method != 'POST':
|
||||||
|
raise PermissionDenied("This view cannot be accessed")
|
||||||
|
|
||||||
|
# check credentials here
|
||||||
|
|
||||||
|
form = DocumentsForm(request.POST,request.FILES)
|
||||||
|
optionsform = TeamUploadOptionsForm(request.POST)
|
||||||
|
rowerform = TeamInviteForm(request.POST)
|
||||||
|
rowerform.fields.pop('email')
|
||||||
|
if form.is_valid():
|
||||||
|
f = request.FILES.get('file',False)
|
||||||
|
if f:
|
||||||
|
res = handle_uploaded_file(f)
|
||||||
|
else:
|
||||||
|
message = {'message':'no file attached','status':'false'}
|
||||||
|
return JsonResponse(status=400,data=message)
|
||||||
|
|
||||||
|
t = form.cleaned_data['title']
|
||||||
|
offline = True
|
||||||
|
offline = form.cleaned_data['offline']
|
||||||
|
boattype = form.cleaned_data['boattype']
|
||||||
|
workouttype = form.cleaned_data['workouttype']
|
||||||
|
if rowerform.is_valid():
|
||||||
|
u = rowerform.cleaned_data['user']
|
||||||
|
r = getrower(u)
|
||||||
|
else:
|
||||||
|
message = {'status':'false','message':'invalid user'}
|
||||||
|
return JSonResponse(status=400,data=message)
|
||||||
|
|
||||||
|
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']
|
||||||
|
upload_to_strava = optionsform.cleaned_data['upload_to_Strava']
|
||||||
|
upload_to_st = optionsform.cleaned_data['upload_to_SportTracks']
|
||||||
|
upload_to_rk = optionsform.cleaned_data['upload_to_RunKeeper']
|
||||||
|
upload_to_ua = optionsform.cleaned_data['upload_to_MapMyFitness']
|
||||||
|
upload_to_tp = optionsform.cleaned_data['upload_to_TrainingPeaks']
|
||||||
|
makeprivate = optionsform.cleaned_data['makeprivate']
|
||||||
|
landingpage = optionsform.cleaned_data['landingpage']
|
||||||
|
|
||||||
|
uploadoptions = {
|
||||||
|
'makeprivate':makeprivate,
|
||||||
|
'make_plot':make_plot,
|
||||||
|
'plottype':plottype,
|
||||||
|
'upload_to_C2':upload_to_c2,
|
||||||
|
'upload_to_Strava':upload_to_strava,
|
||||||
|
'upload_to_SportTracks':upload_to_st,
|
||||||
|
'upload_to_RunKeeper':upload_to_rk,
|
||||||
|
'upload_to_MapMyFitness':upload_to_ua,
|
||||||
|
'upload_to_TrainingPeaks':upload_to_tp,
|
||||||
|
'landingpage':landingpage,
|
||||||
|
'boattype': boattype,
|
||||||
|
'workouttype': workouttype,
|
||||||
|
}
|
||||||
|
|
||||||
|
f1 = res[0]
|
||||||
|
f2 = res[1]
|
||||||
|
|
||||||
|
id, message, f2 = dataprep.new_workout_from_file(
|
||||||
|
r,f2,
|
||||||
|
workouttype=workouttype,
|
||||||
|
workoutsource=workoutsource,
|
||||||
|
boattype=boattype,
|
||||||
|
makeprivate=makeprivate,
|
||||||
|
title = t,
|
||||||
|
notes=notes,
|
||||||
|
)
|
||||||
|
|
||||||
|
if <= 0:
|
||||||
|
message = {'status':'false','message':'unable to process file'}
|
||||||
|
return JSonResponse(status=400,data=message)
|
||||||
|
|
||||||
|
w = Workout.objects.get(id=id)
|
||||||
|
|
||||||
|
if make_plot:
|
||||||
|
res, jobid = uploads.make_plot(r,w,f1,f2,plottype,t)
|
||||||
|
|
||||||
|
if upload_to_c2:
|
||||||
|
try:
|
||||||
|
message,id = c2stuff.workout_c2_upload(r.user,w)
|
||||||
|
except NoTokenError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# add other export options
|
||||||
|
|
||||||
|
message = {'status': 'true','id':w.id}
|
||||||
|
return JSONResponse(status=200,data=message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# This is the main view for processing uploaded files
|
# This is the main view for processing uploaded files
|
||||||
@login_required()
|
@login_required()
|
||||||
|
|||||||
Reference in New Issue
Block a user