copy/pasts plan to calendar
This commit is contained in:
@@ -1052,6 +1052,27 @@ def get_workouts_session(r,ps):
|
|||||||
|
|
||||||
return ws
|
return ws
|
||||||
|
|
||||||
|
def create_sessions_from_json(plansteps,athletes,startdate,manager):
|
||||||
|
trainingdays = plansteps['plan']['trainingDays']
|
||||||
|
for day in trainingdays:
|
||||||
|
for workout in day['workouts']:
|
||||||
|
ps = PlannedSession(
|
||||||
|
startdate = startdate+timedelta(days=day['order']),
|
||||||
|
enddate = startdate,
|
||||||
|
preferreddate = startdate,
|
||||||
|
sessionsport = 'water', # change this
|
||||||
|
name = workout['workoutName'],
|
||||||
|
steps = workout,
|
||||||
|
manager = manager,
|
||||||
|
sessionmode = 'time',
|
||||||
|
comment = workout['description']
|
||||||
|
)
|
||||||
|
|
||||||
|
ps.save()
|
||||||
|
|
||||||
|
for athlete in athletes:
|
||||||
|
add_rower_session(athlete,ps)
|
||||||
|
|
||||||
def update_plannedsession(ps,cd):
|
def update_plannedsession(ps,cd):
|
||||||
for attr, value in cd.items():
|
for attr, value in cd.items():
|
||||||
if attr == 'comment':
|
if attr == 'comment':
|
||||||
|
|||||||
@@ -10,6 +10,14 @@
|
|||||||
|
|
||||||
<ul class="main-content">
|
<ul class="main-content">
|
||||||
<li class="grid_4">
|
<li class="grid_4">
|
||||||
|
<p>Created by: {{ plan.owner.first_name }} {{ plan.owner.last_name }}</p>
|
||||||
|
<p>Plan length: {{ plan.duration }} days</p>
|
||||||
|
<p>{{ plan.description }}</p>
|
||||||
|
<p>{{ plan.target }}</p>
|
||||||
|
<p>Goal: {{ plan.goal }}</p>
|
||||||
|
<p>{{ plan.hoursperweek }} hours per week</p>
|
||||||
|
</li>
|
||||||
|
<li class="grid_2">
|
||||||
<table width="100%" class="listtable">
|
<table width="100%" class="listtable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -34,6 +42,23 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="grid_2">
|
||||||
|
<p>
|
||||||
|
When you submit this form, a training plan will be created based on {{ plan.name }}, ending at your target date,
|
||||||
|
and the sessions will be copied to your session calendar.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
You can select the end date manually or use the training target (if you have any), and the plan will start at
|
||||||
|
the date it needs to complete in time.
|
||||||
|
</p>
|
||||||
|
<form enctype="multipart/form-data" action="" method="post">
|
||||||
|
<table>
|
||||||
|
{{ form.as_table }}
|
||||||
|
</table>
|
||||||
|
{% csrf_token %}
|
||||||
|
<p><input class="button" type="submit" value="Create Plan and Add Sessions"></p>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -2433,6 +2433,9 @@ def rower_view_instantplan(request,id='',userid=0):
|
|||||||
if not id:
|
if not id:
|
||||||
raise Http404("Plan does not exist")
|
raise Http404("Plan does not exist")
|
||||||
|
|
||||||
|
plan = InstantPlan.objects.get(uuid=id)
|
||||||
|
|
||||||
|
|
||||||
authorizationstring = 'Bearer '+settings.WORKOUTS_FIT_TOKEN
|
authorizationstring = 'Bearer '+settings.WORKOUTS_FIT_TOKEN
|
||||||
url = settings.WORKOUTS_FIT_URL+"/trainingplan/"+id
|
url = settings.WORKOUTS_FIT_URL+"/trainingplan/"+id
|
||||||
headers = {'Authorization':authorizationstring}
|
headers = {'Authorization':authorizationstring}
|
||||||
@@ -2442,13 +2445,13 @@ def rower_view_instantplan(request,id='',userid=0):
|
|||||||
messages.error(request,"Could not connect to the training plan server")
|
messages.error(request,"Could not connect to the training plan server")
|
||||||
return HttpResponseRedirect(reverse('rower_select_instantplan'))
|
return HttpResponseRedirect(reverse('rower_select_instantplan'))
|
||||||
|
|
||||||
plan = response.json()
|
plansteps = response.json()
|
||||||
trainingdays = plan['plan']['trainingDays']
|
trainingdays = plansteps['plan']['trainingDays']
|
||||||
|
|
||||||
|
|
||||||
trainingdays2 = []
|
trainingdays2 = []
|
||||||
nextday = trainingdays.pop(0)
|
nextday = trainingdays.pop(0)
|
||||||
for i in range(plan['plan']['duration']):
|
for i in range(plansteps['plan']['duration']):
|
||||||
if nextday['order'] == i+1:
|
if nextday['order'] == i+1:
|
||||||
nextday['week'] = (divmod(i,7)[0])+1
|
nextday['week'] = (divmod(i,7)[0])+1
|
||||||
trainingdays2.append(nextday)
|
trainingdays2.append(nextday)
|
||||||
@@ -2465,6 +2468,61 @@ def rower_view_instantplan(request,id='',userid=0):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
targets = TrainingTarget.objects.filter(
|
||||||
|
rowers=r,
|
||||||
|
date__gte=datetime.date.today(),
|
||||||
|
).order_by("-date")
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = TrainingPlanForm(request.POST,user=request.user)
|
||||||
|
if form.is_valid():
|
||||||
|
plansteps = response.json()
|
||||||
|
name = form.cleaned_data['name']
|
||||||
|
try:
|
||||||
|
target = form.cleaned_data['target']
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
targetid = request.POST['target']
|
||||||
|
if targetid != '':
|
||||||
|
target = TrainingTarget.ojects.get(id=int(targetid))
|
||||||
|
else:
|
||||||
|
target = None
|
||||||
|
except KeyError:
|
||||||
|
target = None
|
||||||
|
enddate = form.cleaned_data['enddate']
|
||||||
|
notes = form.cleaned_data['notes']
|
||||||
|
status = form.cleaned_data['status']
|
||||||
|
if target:
|
||||||
|
enddate = target.date
|
||||||
|
|
||||||
|
startdate = enddate-datetime.timedelta(days=plan.duration+1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
athletes = form.cleaned_data['rowers']
|
||||||
|
except KeyError:
|
||||||
|
athletes = [r]
|
||||||
|
|
||||||
|
p = TrainingPlan(
|
||||||
|
name=name,
|
||||||
|
target=target,
|
||||||
|
manager=r,
|
||||||
|
startdate=startdate,
|
||||||
|
enddate=enddate,status=status,
|
||||||
|
notes=notes,
|
||||||
|
)
|
||||||
|
|
||||||
|
p.save()
|
||||||
|
|
||||||
|
for athlete in athletes:
|
||||||
|
if can_plan_user(request.user,athlete):
|
||||||
|
p.rowers.add(athlete)
|
||||||
|
|
||||||
|
create_sessions_from_json(plansteps,athletes,startdate,r.user)
|
||||||
|
|
||||||
|
else:
|
||||||
|
form = TrainingPlanForm(targets=targets,initial={'status':True,'rowers':[r]},
|
||||||
|
user=request.user)
|
||||||
|
|
||||||
breadcrumbs = [
|
breadcrumbs = [
|
||||||
{
|
{
|
||||||
'url':reverse('plannedsessions_view'),
|
'url':reverse('plannedsessions_view'),
|
||||||
@@ -2484,7 +2542,7 @@ def rower_view_instantplan(request,id='',userid=0):
|
|||||||
'id':id,
|
'id':id,
|
||||||
# 'userid':userid,
|
# 'userid':userid,
|
||||||
}),
|
}),
|
||||||
'name':plan['name']
|
'name':plan.name
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2495,6 +2553,8 @@ def rower_view_instantplan(request,id='',userid=0):
|
|||||||
'active':'nav-plan',
|
'active':'nav-plan',
|
||||||
'plan': plan,
|
'plan': plan,
|
||||||
'trainingdays':trainingdays2,
|
'trainingdays':trainingdays2,
|
||||||
|
'breadcrumbs':breadcrumbs,
|
||||||
|
'form':form,
|
||||||
})
|
})
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
|
|||||||
Reference in New Issue
Block a user