allows to download updated plans
This commit is contained in:
@@ -154,6 +154,12 @@
|
|||||||
href="/rowers/sessions/sendcalendar/user/{{ rower.user.id }}/?when={{ timeperiod }}">
|
href="/rowers/sessions/sendcalendar/user/{{ rower.user.id }}/?when={{ timeperiod }}">
|
||||||
Get Calendar File</a>
|
Get Calendar File</a>
|
||||||
|
|
||||||
|
{% if user.is_authenticated and user.is_staff %}
|
||||||
|
<a
|
||||||
|
href="/rowers/sessions/saveasplan/user/{{ rower.user.id }}/?when={{ timeperiod }}">
|
||||||
|
Save to YaML</a>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
<a
|
<a
|
||||||
href="/rowers/plan/0/execution/?when={{ timeperiod }}/">
|
href="/rowers/plan/0/execution/?when={{ timeperiod }}/">
|
||||||
Actual vs Plan chart
|
Actual vs Plan chart
|
||||||
|
|||||||
@@ -1055,6 +1055,10 @@ urlpatterns = [
|
|||||||
name='plannedsessions_coach_icsemail_view'),
|
name='plannedsessions_coach_icsemail_view'),
|
||||||
re_path(r'^sessions/sendcalendar/user/(?P<userid>\d+)/$', views.plannedsessions_icsemail_view,
|
re_path(r'^sessions/sendcalendar/user/(?P<userid>\d+)/$', views.plannedsessions_icsemail_view,
|
||||||
name='plannedsessions_icsemail_view'),
|
name='plannedsessions_icsemail_view'),
|
||||||
|
re_path(r'^sessions/saveasplan/$', views.save_plan_yaml,
|
||||||
|
name='save_plan_yaml'),
|
||||||
|
re_path(r'^sessions/saveasplan/user/(?P<userid>\d+)/$', views.save_plan_yaml,
|
||||||
|
name='save_plan_yaml'),
|
||||||
re_path(r'^sessions/$', views.plannedsessions_view,
|
re_path(r'^sessions/$', views.plannedsessions_view,
|
||||||
name='plannedsessions_view'),
|
name='plannedsessions_view'),
|
||||||
re_path(r'^sessions/user/(?P<userid>\d+)/$', views.plannedsessions_view,
|
re_path(r'^sessions/user/(?P<userid>\d+)/$', views.plannedsessions_view,
|
||||||
|
|||||||
@@ -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()
|
@login_required()
|
||||||
def plannedsessions_view(request,
|
def plannedsessions_view(request,
|
||||||
|
|||||||
Reference in New Issue
Block a user