allows to download updated plans
This commit is contained in:
@@ -1375,6 +1375,55 @@ def plannedsessions_coach_view(request,
|
||||
}
|
||||
)
|
||||
|
||||
@login_required()
|
||||
def save_plan_yaml(request, userid=0):
|
||||
r = getrequestrower(request, userid=userid)
|
||||
startdate, enddate = get_dates_timeperiod(request)
|
||||
startdate = startdate.date()
|
||||
enddate = enddate.date()
|
||||
|
||||
duration = (enddate-startdate).days+1
|
||||
filename = 'myplan.yml'
|
||||
|
||||
plan = {
|
||||
'filename': filename,
|
||||
'name': 'Training Plan',
|
||||
'duration': duration,
|
||||
'description': 'My Training Plan',
|
||||
}
|
||||
|
||||
sps = get_sessions(r, startdate=startdate, enddate=enddate)
|
||||
|
||||
trainingdays = []
|
||||
|
||||
# add sessions to days
|
||||
for i in range(duration):
|
||||
dd = startdate+timedelta(days=i)
|
||||
workouts = []
|
||||
for ps in sps:
|
||||
if ps.preferreddate == dd:
|
||||
sessionsport = mytypes.fitmapping[ps.sessionsport].capitalize()
|
||||
steps = ps.steps
|
||||
steps['filename'] = ""
|
||||
workouts.append(steps)
|
||||
|
||||
trainingdays.append({'order': i+1, 'workouts': workouts})
|
||||
|
||||
plan['trainingDays'] = trainingdays
|
||||
|
||||
response = HttpResponse(yaml.dump(plan))
|
||||
|
||||
response['Content-Disposition'] = 'attachment; filename="training_plan_{u}_{d1}_{d2}.yml"'.format(
|
||||
u=request.user.username,
|
||||
d1=startdate.strftime("%Y%m%d"),
|
||||
d2=enddate.strftime("%Y%m%d"),
|
||||
)
|
||||
|
||||
response['Content-Type'] = 'application/octet-stream'
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
||||
@login_required()
|
||||
def plannedsessions_view(request,
|
||||
|
||||
Reference in New Issue
Block a user