Private
Public Access
1
0

form improvements

This commit is contained in:
Sander Roosendaal
2021-03-26 02:44:39 +01:00
parent 3bdcac6963
commit cf4dd9e128
3 changed files with 24 additions and 10 deletions

View File

@@ -60,35 +60,45 @@ class FlexibleDecimalField(forms.DecimalField):
class InstantPlanSelectForm(forms.Form): class InstantPlanSelectForm(forms.Form):
datechoices = ( datechoices = (
('start date','startdate'), ('startdate','start date'),
('end date', 'enddate'), ('enddate', 'end date'),
('target','target') ('target','target')
) )
name = forms.CharField(max_length=255,label='Plan Name',required=False) name = forms.CharField(max_length=255,label='Plan Name',required=False)
startdate = forms.DateField( startdate = forms.DateField(
initial=timezone.now()-datetime.timedelta(days=15), initial=timezone.now(),
# widget=SelectDateWidget(years=range(1990,2050)), # widget=SelectDateWidget(years=range(1990,2050)),
widget=AdminDateWidget(), #format='%Y-%m-%d'), widget=AdminDateWidget(), #format='%Y-%m-%d'),
label='Start Date') label='Start Date')
enddate = forms.DateField( enddate = forms.DateField(
initial=timezone.now(), initial=timezone.now()+datetime.timedelta(days=21),
widget=AdminDateWidget(), #format='%Y-%m-%d'), widget=AdminDateWidget(), #format='%Y-%m-%d'),
label='End Date') label='End Date')
target = forms.ChoiceField(required=False) target = forms.ChoiceField(required=False)
datechoice = forms.ChoiceField(choices=datechoices,initial='enddate',label='Plan by target, start or end date') datechoice = forms.ChoiceField(choices=datechoices,initial='enddate',label='Plan by target, start or end date',
widget=forms.RadioSelect)
notes = forms.CharField(required=False, notes = forms.CharField(required=False,
max_length=200,label='Course Notes', max_length=200,label='Course Notes',
widget=forms.Textarea) widget=forms.Textarea)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
targets = kwargs.pop('targets',None) targets = kwargs.pop('targets',None)
instantplan = kwargs.pop('instantplan',None)
super(InstantPlanSelectForm, self).__init__(*args, **kwargs) super(InstantPlanSelectForm, self).__init__(*args, **kwargs)
if targets: if targets:
targetchoices = [(x.id,x) for x in targets] targetchoices = [(x.id,x) for x in targets]
targetchoices.append((None,'---')) targetchoices.append((None,'---'))
self.fields['target'].choices = targetchoices self.fields['target'].choices = targetchoices
else: else:
datechoices = (
('startdate','start date'),
('enddate', 'end date'),
)
self.fields['datechoice'].choices = datechoices
self.fields['datechoice'].label = 'Plan by start or end date'
self.fields.pop('target') self.fields.pop('target')
if instantplan:
self.fields['enddate'].initial = timezone.now()+datetime.timedelta(days=instantplan.duration)

View File

@@ -36,12 +36,16 @@
{% if form %} {% if form %}
<li class="grid_2"> <li class="grid_2">
<p> <p>
When you submit this form, a training plan will be created based on {{ plan.name }}, ending at your target date, When you submit this form, a training plan will be created based on {{ plan.name }}. The sessions
and the sessions will be copied to your session calendar. will be copied to your training calendar.
</p> </p>
<p> <p>
You can select the end date manually or use the training target (if you have any), and the plan will start at You can plan by when you want the plan to start or by when you want it to
the date it needs to complete in time. be done.
</p>
<p>
If you have <a href="/rowers/createplan/">set a training target</a>, you can also ask to plan by that target. Select the
target from the targets list, and select "plan by target".
</p> </p>
{% if plan.price == 0 %} {% if plan.price == 0 %}
<form enctype="multipart/form-data" action="" method="post"> <form enctype="multipart/form-data" action="" method="post">

View File

@@ -2576,7 +2576,7 @@ def rower_view_instantplan(request,id='',userid=0):
elif not request.user.is_anonymous: elif not request.user.is_anonymous:
form = InstantPlanSelectForm(targets=targets) form = InstantPlanSelectForm(targets=targets,instantplan=plan,initial={'datechoice':'startdate'})
else: else:
form = None form = None