From ac664cb511cf12ef9a674b27f049d8a3aae863cc Mon Sep 17 00:00:00 2001 From: Jean-Louis Jouannic Date: Wed, 6 Jul 2022 21:39:37 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20applies=20new=20child=20selection?= =?UTF-8?q?=20widget=20to=20all=20forms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit filters out blank option for timer form as it does not really make sense to allow user to select no child --- core/forms.py | 18 ++++++++++++++++-- core/templates/core/child_radio.html | 2 ++ core/widgets.py | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/forms.py b/core/forms.py index 13cbeaab..15acc73b 100644 --- a/core/forms.py +++ b/core/forms.py @@ -143,6 +143,7 @@ class PumpingForm(CoreModelForm): model = models.Pumping fields = ["child", "amount", "time", "notes"] widgets = { + "child": ChildRadioSelect, "time": forms.DateTimeInput( attrs={ "autocomplete": "off", @@ -156,8 +157,10 @@ class PumpingForm(CoreModelForm): class DiaperChangeForm(CoreModelForm, TaggableModelForm): class Meta: model = models.DiaperChange - fields = ["child", "time", "wet", "solid", "color", "amount", "notes", "tags"] + fields = ["child", "time", "wet", "solid", "color", "amount", "notes", + "tags"] widgets = { + "child": ChildRadioSelect(), "time": forms.DateTimeInput( attrs={ "autocomplete": "off", @@ -171,7 +174,8 @@ class DiaperChangeForm(CoreModelForm, TaggableModelForm): class FeedingForm(CoreModelForm, TaggableModelForm): class Meta: model = models.Feeding - fields = ["child", "start", "end", "type", "method", "amount", "notes", "tags"] + fields = ["child", "start", "end", "type", "method", "amount", "notes", + "tags"] widgets = { "child": ChildRadioSelect, "start": forms.DateTimeInput( @@ -195,6 +199,7 @@ class NoteForm(CoreModelForm, TaggableModelForm): model = models.Note fields = ["child", "note", "time", "tags"] widgets = { + "child": ChildRadioSelect, "time": forms.DateTimeInput( attrs={ "autocomplete": "off", @@ -209,6 +214,7 @@ class SleepForm(CoreModelForm, TaggableModelForm): model = models.Sleep fields = ["child", "start", "end", "notes", "tags"] widgets = { + "child": ChildRadioSelect, "start": forms.DateTimeInput( attrs={ "autocomplete": "off", @@ -230,6 +236,7 @@ class TemperatureForm(CoreModelForm, TaggableModelForm): model = models.Temperature fields = ["child", "temperature", "time", "notes", "tags"] widgets = { + "child": ChildRadioSelect, "time": forms.DateTimeInput( attrs={ "autocomplete": "off", @@ -241,10 +248,12 @@ class TemperatureForm(CoreModelForm, TaggableModelForm): class TimerForm(CoreModelForm): + class Meta: model = models.Timer fields = ["child", "name", "start"] widgets = { + "child": ChildRadioSelect, "start": forms.DateTimeInput( attrs={ "autocomplete": "off", @@ -269,6 +278,7 @@ class TummyTimeForm(CoreModelForm, TaggableModelForm): model = models.TummyTime fields = ["child", "start", "end", "milestone", "tags"] widgets = { + "child": ChildRadioSelect, "start": forms.DateTimeInput( attrs={ "autocomplete": "off", @@ -289,6 +299,7 @@ class WeightForm(CoreModelForm, TaggableModelForm): model = models.Weight fields = ["child", "weight", "date", "notes", "tags"] widgets = { + "child": ChildRadioSelect, "date": forms.DateInput( attrs={ "autocomplete": "off", @@ -304,6 +315,7 @@ class HeightForm(CoreModelForm, TaggableModelForm): model = models.Height fields = ["child", "height", "date", "notes", "tags"] widgets = { + "child": ChildRadioSelect, "date": forms.DateInput( attrs={ "autocomplete": "off", @@ -319,6 +331,7 @@ class HeadCircumferenceForm(CoreModelForm, TaggableModelForm): model = models.HeadCircumference fields = ["child", "head_circumference", "date", "notes", "tags"] widgets = { + "child": ChildRadioSelect, "date": forms.DateInput( attrs={ "autocomplete": "off", @@ -334,6 +347,7 @@ class BMIForm(CoreModelForm, TaggableModelForm): model = models.BMI fields = ["child", "bmi", "date", "notes", "tags"] widgets = { + "child": ChildRadioSelect, "date": forms.DateInput( attrs={ "autocomplete": "off", diff --git a/core/templates/core/child_radio.html b/core/templates/core/child_radio.html index 967d6847..634a9b79 100644 --- a/core/templates/core/child_radio.html +++ b/core/templates/core/child_radio.html @@ -2,7 +2,9 @@ {% for group, options, index in widget.optgroups %} {% for option in options %} + {% if option.value != '' %} {% include option.template_name with widget=option %} + {% endif %} {% endfor %} {% endfor %} {% endwith %} diff --git a/core/widgets.py b/core/widgets.py index 8860a7a1..de2383fc 100644 --- a/core/widgets.py +++ b/core/widgets.py @@ -90,5 +90,6 @@ class ChildRadioSelect(RadioSelect): def create_option(self, name, value, label, selected, index, subindex=None, attrs=None): option = super().create_option(name, value, label, selected, index, subindex, attrs) - option['picture'] = value.instance.picture + if value != '': + option['picture'] = value.instance.picture return option