Skip to content

Commit d96a12e

Browse files
authored
Refactor responses to their own models (#195)
* Move HaveYouEverSmokedResponse to its own model * Move AsbestosExposureResponse to its own model * Move DateOfBirthResponse to its own model * Move EthnicityResponse to its own model * Move GenderResponse to its own model * Move HeightResponse to its own model * Move RespiratoryConditionsResponse to its own model * Move SexAtBirthResponse to its own model * Move WeightResponse to its own model * Cleanup old ResponseSet model * Add presenter for ResponseSet presentation layer
1 parent 06d6ffb commit d96a12e

File tree

93 files changed

+2044
-899
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2044
-899
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from django import forms
22
from ...nhsuk_forms.typed_choice_field import TypedChoiceField
3-
from ..models.response_set import ResponseSet
3+
from ..models.asbestos_exposure_response import AsbestosExposureResponse
44

55

66
class AsbestosExposureForm(forms.ModelForm):
77
def __init__(self, *args, **kwargs):
88
super().__init__(*args, **kwargs)
99

10-
self.fields["asbestos_exposure"] = TypedChoiceField(
10+
self.fields["value"] = TypedChoiceField(
1111
choices=[(True, 'Yes'), (False, 'No')],
1212
widget=forms.RadioSelect,
1313
label="Have you ever worked in a job where you might have been exposed to asbestos?",
@@ -19,5 +19,5 @@ def __init__(self, *args, **kwargs):
1919
)
2020

2121
class Meta:
22-
model = ResponseSet
23-
fields = ['asbestos_exposure']
22+
model = AsbestosExposureResponse
23+
fields = ['value']

lung_cancer_screening/questions/forms/date_of_birth_form.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django import forms
22
from datetime import date
33

4-
from ..models.response_set import ResponseSet
4+
from ..models.date_of_birth_response import DateOfBirthResponse
55
from ...nhsuk_forms.split_date_field import SplitDateField
66

77

@@ -10,7 +10,7 @@ def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111

1212
invalid_error_message = 'Date of birth must be a real date'
13-
self.fields["date_of_birth"] = SplitDateField(
13+
self.fields["value"] = SplitDateField(
1414
max_value=date.today(),
1515
required=True,
1616
require_all_fields=False,
@@ -28,5 +28,5 @@ def __init__(self, *args, **kwargs):
2828
)
2929

3030
class Meta:
31-
model = ResponseSet
32-
fields = ['date_of_birth']
31+
model = DateOfBirthResponse
32+
fields = ['value']

lung_cancer_screening/questions/forms/ethnicity_form.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from django import forms
22

33
from ...nhsuk_forms.choice_field import ChoiceField
4-
from ..models.response_set import ResponseSet, EthnicityValues
4+
from ..models.ethnicity_response import EthnicityResponse, EthnicityValues
55

66

77
class EthnicityForm(forms.ModelForm):
88

99
def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111

12-
self.fields["ethnicity"] = ChoiceField(
12+
self.fields["value"] = ChoiceField(
1313
choices=EthnicityValues.choices,
1414
label="What is your ethnic background?",
1515
widget=forms.RadioSelect,
@@ -24,10 +24,10 @@ def __init__(self, *args, **kwargs):
2424
}
2525
)
2626

27-
self["ethnicity"].add_divider_after(
27+
self["value"].add_divider_after(
2828
EthnicityValues.OTHER.value, "or"
2929
)
3030

3131
class Meta:
32-
model = ResponseSet
33-
fields = ['ethnicity']
32+
model = EthnicityResponse
33+
fields = ['value']

lung_cancer_screening/questions/forms/gender_form.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from django import forms
22

33
from ...nhsuk_forms.choice_field import ChoiceField
4-
from ..models.response_set import ResponseSet, GenderValues
4+
from ..models.gender_response import GenderResponse, GenderValues
55

66

77
class GenderForm(forms.ModelForm):
88

99
def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111

12-
self.fields["gender"] = ChoiceField(
12+
self.fields["value"] = ChoiceField(
1313
choices=GenderValues.choices,
1414
widget=forms.RadioSelect,
1515
label="Which of these best describes you?",
@@ -25,5 +25,5 @@ def __init__(self, *args, **kwargs):
2525
)
2626

2727
class Meta:
28-
model = ResponseSet
29-
fields = ['gender']
28+
model = GenderResponse
29+
fields = ['value']

lung_cancer_screening/questions/forms/have_you_ever_smoked_form.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from django import forms
22

33
from ...nhsuk_forms.typed_choice_field import TypedChoiceField
4-
from ..models.response_set import ResponseSet, HaveYouEverSmokedValues
4+
from ..models.have_you_ever_smoked_response import HaveYouEverSmokedResponse, HaveYouEverSmokedValues
55

66
class HaveYouEverSmokedForm(forms.ModelForm):
77

88
def __init__(self, *args, **kwargs):
99
super().__init__(*args, **kwargs)
1010

11-
self.fields["have_you_ever_smoked"] = TypedChoiceField(
11+
self.fields["value"] = TypedChoiceField(
1212
choices=HaveYouEverSmokedValues.choices,
1313
widget=forms.RadioSelect,
1414
label="Have you ever smoked?",
@@ -21,5 +21,5 @@ def __init__(self, *args, **kwargs):
2121
)
2222

2323
class Meta:
24-
model = ResponseSet
25-
fields = ['have_you_ever_smoked']
24+
model = HaveYouEverSmokedResponse
25+
fields = ['value']
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from django import forms
22

33
from ...nhsuk_forms.imperial_height_field import ImperialHeightField
4-
from ..models.response_set import ResponseSet
4+
from ..models.height_response import HeightResponse
55

66

77
class ImperialHeightForm(forms.ModelForm):
88

99
def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111

12-
self.fields["height_imperial"] = ImperialHeightField(
12+
self.fields["imperial"] = ImperialHeightField(
1313
label="Height",
1414
required=True,
1515
require_all_fields=False,
@@ -18,9 +18,9 @@ def __init__(self, *args, **kwargs):
1818
}
1919
)
2020

21-
def clean_height(self):
21+
def clean_metric(self):
2222
return None
2323

2424
class Meta:
25-
model = ResponseSet
26-
fields = ['height_imperial', 'height_metric']
25+
model = HeightResponse
26+
fields = ['imperial', 'metric']
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from django import forms
22

33
from ...nhsuk_forms.imperial_weight_field import ImperialWeightField
4-
from ..models.response_set import ResponseSet
4+
from ..models.weight_response import WeightResponse
55

66

77
class ImperialWeightForm(forms.ModelForm):
88

99
def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111

12-
self.fields["weight_imperial"] = ImperialWeightField(
12+
self.fields["imperial"] = ImperialWeightField(
1313
label="Weight",
1414
required=True,
1515
require_all_fields=False,
@@ -18,9 +18,9 @@ def __init__(self, *args, **kwargs):
1818
}
1919
)
2020

21-
def clean_weight_metric(self):
21+
def clean_metric(self):
2222
return None
2323

2424
class Meta:
25-
model = ResponseSet
26-
fields = ['weight_imperial', 'weight_metric']
25+
model = WeightResponse
26+
fields = ['imperial', 'metric']
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django import forms
22

33
from ...nhsuk_forms.decimal_field import DecimalField
4-
from ..models.response_set import ResponseSet
4+
from ..models.height_response import HeightResponse
55

66

77
class MetricHeightForm(forms.ModelForm):
@@ -10,10 +10,10 @@ def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111

1212
# Convert mm to cm for display
13-
if self.instance and self.instance.height_metric is not None:
14-
self.initial['height_metric'] = self.instance.height_metric / 10
13+
if self.instance and self.instance.metric is not None:
14+
self.initial['metric'] = self.instance.metric / 10
1515

16-
self.fields["height_metric"] = DecimalField(
16+
self.fields["metric"] = DecimalField(
1717
decimal_places=1,
1818
label="Centimetres",
1919
classes="nhsuk-input--width-4",
@@ -27,12 +27,12 @@ def __init__(self, *args, **kwargs):
2727
suffix="cm"
2828
)
2929

30-
def clean_height_metric(self):
31-
return self.cleaned_data['height_metric'] * 10
30+
def clean_metric(self):
31+
return int(self.cleaned_data['metric'] * 10)
3232

33-
def clean_height_imperial(self):
33+
def clean_imperial(self):
3434
return None
3535

3636
class Meta:
37-
model = ResponseSet
38-
fields = ['height_metric', 'height_imperial']
37+
model = HeightResponse
38+
fields = ['metric', 'imperial']
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django import forms
22

33
from ...nhsuk_forms.decimal_field import DecimalField
4-
from ..models.response_set import ResponseSet
4+
from ..models.weight_response import WeightResponse
55

66

77
class MetricWeightForm(forms.ModelForm):
@@ -10,10 +10,10 @@ def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111

1212
# Convert hundreds of grams to kg for display
13-
if self.instance and self.instance.weight_metric is not None:
14-
self.initial['weight_metric'] = self.instance.weight_metric / 10
13+
if self.instance and self.instance.metric is not None:
14+
self.initial['metric'] = self.instance.metric / 10
1515

16-
self.fields["weight_metric"] = DecimalField(
16+
self.fields["metric"] = DecimalField(
1717
decimal_places=1,
1818
label="Kilograms",
1919
classes="nhsuk-input--width-4",
@@ -28,12 +28,12 @@ def __init__(self, *args, **kwargs):
2828
suffix="kg"
2929
)
3030

31-
def clean_weight_metric(self):
32-
return self.cleaned_data['weight_metric'] * 10
31+
def clean_metric(self):
32+
return int(self.cleaned_data['metric'] * 10)
3333

34-
def clean_weight_imperial(self):
34+
def clean_imperial(self):
3535
return None
3636

3737
class Meta:
38-
model = ResponseSet
39-
fields = ['weight_metric', 'weight_imperial']
38+
model = WeightResponse
39+
fields = ['metric', 'imperial']

lung_cancer_screening/questions/forms/respiratory_conditions_form.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from django import forms
22

33
from ...nhsuk_forms.choice_field import MultipleChoiceField
4-
from ..models.response_set import ResponseSet, RespiratoryConditionValues
4+
from ..models.respiratory_conditions_response import RespiratoryConditionsResponse, RespiratoryConditionValues
55

66

77
class RespiratoryConditionsForm(forms.ModelForm):
88

99
def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111

12-
self.fields["respiratory_conditions"] = MultipleChoiceField(
12+
self.fields["value"] = MultipleChoiceField(
1313
choices=RespiratoryConditionValues.choices,
1414
widget=forms.CheckboxSelectMultiple,
1515
label=(
@@ -31,7 +31,7 @@ def __init__(self, *args, **kwargs):
3131
)
3232

3333
# Add hints for each choice
34-
respiratory_conditions_field = self["respiratory_conditions"]
34+
respiratory_conditions_field = self["value"]
3535
respiratory_conditions_field.add_hint_for_choice(
3636
RespiratoryConditionValues.PNEUMONIA,
3737
"An infection of the lungs, usually diagnosed by a chest x-ray"
@@ -66,5 +66,5 @@ def __init__(self, *args, **kwargs):
6666
)
6767

6868
class Meta:
69-
model = ResponseSet
70-
fields = ['respiratory_conditions']
69+
model = RespiratoryConditionsResponse
70+
fields = ['value']

0 commit comments

Comments
 (0)