copy/pasts plan to calendar
This commit is contained in:
@@ -2433,6 +2433,9 @@ def rower_view_instantplan(request,id='',userid=0):
|
||||
if not id:
|
||||
raise Http404("Plan does not exist")
|
||||
|
||||
plan = InstantPlan.objects.get(uuid=id)
|
||||
|
||||
|
||||
authorizationstring = 'Bearer '+settings.WORKOUTS_FIT_TOKEN
|
||||
url = settings.WORKOUTS_FIT_URL+"/trainingplan/"+id
|
||||
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")
|
||||
return HttpResponseRedirect(reverse('rower_select_instantplan'))
|
||||
|
||||
plan = response.json()
|
||||
trainingdays = plan['plan']['trainingDays']
|
||||
plansteps = response.json()
|
||||
trainingdays = plansteps['plan']['trainingDays']
|
||||
|
||||
|
||||
trainingdays2 = []
|
||||
nextday = trainingdays.pop(0)
|
||||
for i in range(plan['plan']['duration']):
|
||||
for i in range(plansteps['plan']['duration']):
|
||||
if nextday['order'] == i+1:
|
||||
nextday['week'] = (divmod(i,7)[0])+1
|
||||
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 = [
|
||||
{
|
||||
'url':reverse('plannedsessions_view'),
|
||||
@@ -2484,7 +2542,7 @@ def rower_view_instantplan(request,id='',userid=0):
|
||||
'id':id,
|
||||
# 'userid':userid,
|
||||
}),
|
||||
'name':plan['name']
|
||||
'name':plan.name
|
||||
}
|
||||
]
|
||||
|
||||
@@ -2493,8 +2551,10 @@ def rower_view_instantplan(request,id='',userid=0):
|
||||
{
|
||||
'rower':r,
|
||||
'active':'nav-plan',
|
||||
'plan':plan,
|
||||
'plan': plan,
|
||||
'trainingdays':trainingdays2,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'form':form,
|
||||
})
|
||||
|
||||
@login_required()
|
||||
|
||||
Reference in New Issue
Block a user