Private
Public Access
1
0

some fixes and more user friendly form to buy instantplan

This commit is contained in:
Sander Roosendaal
2021-03-25 08:18:06 +01:00
parent 389119144a
commit 9137b19914
5 changed files with 74 additions and 24 deletions

View File

@@ -109,7 +109,7 @@ def buy_trainingplan_view(request,id=0):
if request.method == 'POST':
billingaddressform = RowerBillingAddressForm(instance=r)
form = TrainingPlanForm(request.POST,user=request.user)
form = InstantPlanSelectForm(request.POST)
if billingaddressform.is_valid():
cd = billingaddressform.cleaned_data
for attr, value in cd.items():
@@ -121,8 +121,10 @@ def buy_trainingplan_view(request,id=0):
cd = form.cleaned_data
enddate = cd['enddate']
startdate = cd['startdate']
notes = cd['notes']
status = cd['status']
datechoice = form.cleaned_data['datechoice']
status = True
# get target and set enddate
try:
@@ -138,8 +140,12 @@ def buy_trainingplan_view(request,id=0):
except KeyError:
target = None
if target:
if target and datechoice == 'target':
enddate = target.date
elif datechoice == 'startdate':
enddate = startdate+datetime.timedelta(days=plan.duration)
else:
startdate = enddate-datetime.timedelta(days=plan.duration)
pars = {
'name':cd['name'],
@@ -154,7 +160,7 @@ def buy_trainingplan_view(request,id=0):
return HttpResponseRedirect(url)
else:
form = TrainingPlanForm(user=request.user)
form = InstantPlanForm()
billingaddressform = RowerBillingAddressForm(instance=r)
return render(request,
@@ -243,9 +249,12 @@ def purchase_checkouts_view(request):
url = reverse("purchase_checkouts_view")
return HttpResponseRedirect(url)
url = reverse('rower_view_instantplan',kwargs={
'id':plan.uuid,
})
url = reverse('rower_select_instantplan')
if 'plan' in request.POST:
plan = plan = InstantPlan.objects.get(id=request.POST['plan'])
url = reverse('rower_view_instantplan',kwargs={
'id':plan.uuid,
})
return HttpResponseRedirect(url)
@user_passes_test(can_plan,login_url="/rowers/paidplans",

View File

@@ -2517,14 +2517,15 @@ def rower_view_instantplan(request,id='',userid=0):
date__gte=datetime.date.today(),
).order_by("-date")
if request.method == 'POST':
if request.method == 'POST' and not request.user.is_anonymous:
if not can_plan(request.user):
messages.error(request,'You must be on a <a href="/rowers/paidplans">paid plan</a> to use this functionality')
url = reverse('rower_view_instantplan',kwargs={
'id':id,
})
return HttpResponseRedirect(url)
form = TrainingPlanForm(request.POST,user=request.user)
form = InstantPlanSelectForm(request.POST)
if form.is_valid():
plansteps = response.json()
@@ -2541,17 +2542,17 @@ def rower_view_instantplan(request,id='',userid=0):
except KeyError:
target = None
enddate = form.cleaned_data['enddate']
startdate = form.cleaned_data['startdate']
notes = form.cleaned_data['notes']
status = form.cleaned_data['status']
if target:
datechoice = form.cleaned_data['datechoice']
status = True
if target and datechoice == 'target':
enddate = target.date
elif datechoice == 'startdate':
enddate = startdate+datetime.timedelta(days=plan.duration)
else:
startdate = enddate-datetime.timedelta(days=plan.duration)
startdate = enddate-datetime.timedelta(days=plan.duration+1)
try:
athletes = form.cleaned_data['rowers']
except KeyError:
athletes = [r]
p = TrainingPlan(
name=name,
@@ -2563,10 +2564,7 @@ def rower_view_instantplan(request,id='',userid=0):
)
p.save()
for athlete in athletes:
if can_plan_user(request.user,athlete):
p.rowers.add(athlete)
p.rowers.add(r)
create_sessions_from_json(plansteps,athletes,startdate,r.user)
@@ -2577,9 +2575,10 @@ def rower_view_instantplan(request,id='',userid=0):
return HttpResponseRedirect(url)
elif not request.user.is_anonymous:
form = InstantPlanSelectForm(targets=targets)
else:
form = TrainingPlanForm(targets=targets,initial={'status':True,'rowers':[r]},
user=request.user)
form = None
breadcrumbs = [
{

View File

@@ -77,7 +77,7 @@ from rowers.forms import (
VideoAnalysisCreateForm,WorkoutSingleSelectForm,
VideoAnalysisMetricsForm,SurveyForm,HistorySelectForm,
StravaChartForm,FitnessFitForm,PerformanceManagerForm,
TrainingPlanBillingForm,
TrainingPlanBillingForm,InstantPlanSelectForm
)
from django.urls import reverse, reverse_lazy