From cf4dd9e128bd270f66a1c4d7cdf043fa29d1530d Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 26 Mar 2021 02:44:39 +0100 Subject: [PATCH] form improvements --- rowers/forms.py | 20 +++++++++++++++----- rowers/templates/instantplan.html | 12 ++++++++---- rowers/views/planviews.py | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/rowers/forms.py b/rowers/forms.py index 639631a4..86477e44 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -60,35 +60,45 @@ class FlexibleDecimalField(forms.DecimalField): class InstantPlanSelectForm(forms.Form): datechoices = ( - ('start date','startdate'), - ('end date', 'enddate'), + ('startdate','start date'), + ('enddate', 'end date'), ('target','target') ) name = forms.CharField(max_length=255,label='Plan Name',required=False) startdate = forms.DateField( - initial=timezone.now()-datetime.timedelta(days=15), + initial=timezone.now(), # widget=SelectDateWidget(years=range(1990,2050)), widget=AdminDateWidget(), #format='%Y-%m-%d'), label='Start Date') enddate = forms.DateField( - initial=timezone.now(), + initial=timezone.now()+datetime.timedelta(days=21), widget=AdminDateWidget(), #format='%Y-%m-%d'), label='End Date') 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, max_length=200,label='Course Notes', widget=forms.Textarea) def __init__(self, *args, **kwargs): targets = kwargs.pop('targets',None) + instantplan = kwargs.pop('instantplan',None) super(InstantPlanSelectForm, self).__init__(*args, **kwargs) if targets: targetchoices = [(x.id,x) for x in targets] targetchoices.append((None,'---')) self.fields['target'].choices = targetchoices 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') + if instantplan: + self.fields['enddate'].initial = timezone.now()+datetime.timedelta(days=instantplan.duration) diff --git a/rowers/templates/instantplan.html b/rowers/templates/instantplan.html index af8f4498..b581bd5d 100644 --- a/rowers/templates/instantplan.html +++ b/rowers/templates/instantplan.html @@ -36,12 +36,16 @@ {% if form %}
  • - 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. + When you submit this form, a training plan will be created based on {{ plan.name }}. The sessions + will be copied to your training calendar.

    - 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. + You can plan by when you want the plan to start or by when you want it to + be done. +

    +

    + If you have set a training target, you can also ask to plan by that target. Select the + target from the targets list, and select "plan by target".

    {% if plan.price == 0 %}
    diff --git a/rowers/views/planviews.py b/rowers/views/planviews.py index 690e40d4..d5434143 100644 --- a/rowers/views/planviews.py +++ b/rowers/views/planviews.py @@ -2576,7 +2576,7 @@ def rower_view_instantplan(request,id='',userid=0): elif not request.user.is_anonymous: - form = InstantPlanSelectForm(targets=targets) + form = InstantPlanSelectForm(targets=targets,instantplan=plan,initial={'datechoice':'startdate'}) else: form = None