Skip to content

Commit b7cd870

Browse files
committed
Simplify model structure
Dont use a model for each response, use a single ResposeSet to collate all responses
1 parent 5d92c90 commit b7cd870

35 files changed

+264
-307
lines changed

lung_cancer_screening/core/tests/acceptance/test_participant_not_smoker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_participant_not_smoker(self):
3333
expect(page.locator("legend")).to_have_text(
3434
"Have you ever smoked?")
3535

36-
page.get_by_label('No').check()
36+
page.get_by_label('No, I have never smoked').check()
3737

3838
page.click("text=Continue")
3939

lung_cancer_screening/core/tests/acceptance/test_participant_out_of_age_range.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_participant_out_of_age_range(self):
3636
expect(page.locator("legend")).to_have_text(
3737
"Have you ever smoked?")
3838

39-
page.get_by_label('Yes').check()
39+
page.get_by_label('Yes, I used to smoke regularly').check()
4040

4141
page.click("text=Continue")
4242

lung_cancer_screening/core/tests/acceptance/test_questionnaire.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_full_questionaire_user_journey(self):
3535
expect(page.locator("legend")).to_have_text(
3636
"Have you ever smoked?")
3737

38-
page.get_by_label('Yes').check()
38+
page.get_by_label('Yes, I used to smoke regularly').check()
3939

4040
page.click("text=Continue")
4141

@@ -55,5 +55,5 @@ def test_full_questionaire_user_journey(self):
5555
expect(page).to_have_url(f"{self.live_server_url}/responses")
5656

5757
expect(page.locator(".responses")).to_contain_text(
58-
age.strftime("Have you ever smoked? True"))
58+
age.strftime("Have you ever smoked? Yes, I used to smoke regularly"))
5959
expect(page.locator(".responses")).to_contain_text(age.strftime("What is your date of birth? %Y-%m-%d"))

lung_cancer_screening/core/tests/acceptance/test_questionnaire_validation_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_full_questionaire_user_journey_with_validation_errors(self):
3333
expect(page.locator("legend")).to_have_text(
3434
"Have you ever smoked?")
3535

36-
page.get_by_label('Yes').check()
36+
page.get_by_label('Yes, I currently smoke').check()
3737

3838
page.click("text=Continue")
3939

lung_cancer_screening/questions/forms/boolean_response_form.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

lung_cancer_screening/questions/forms/date_response_form.py renamed to lung_cancer_screening/questions/forms/date_of_birth_form.py

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

4-
from ..models.date_response import DateResponse
4+
from ..models.response_set import ResponseSet
55
from lung_cancer_screening.core.form_fields import SplitDateField
66

7-
class DateResponseForm(forms.ModelForm):
7+
class DateOfBirthForm(forms.ModelForm):
88
def __init__(self, *args, **kwargs):
99
super().__init__(*args, **kwargs)
1010

11-
self.fields["value"] = SplitDateField(
11+
self.fields["date_of_birth"] = SplitDateField(
1212
max_value=date.today(),
1313
required=False,
1414
hint="For example, 15 3 2025",
1515
label="What is your date of birth?"
1616
)
1717

1818
class Meta:
19-
model = DateResponse
20-
fields = ['value']
19+
model = ResponseSet
20+
fields = ['date_of_birth']
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django import forms
2+
3+
from lung_cancer_screening.core.form_fields import TypedChoiceField
4+
from ..models.response_set import ResponseSet, HaveYouEverSmokedValues
5+
6+
class HaveYouEverSmokedForm(forms.ModelForm):
7+
8+
def __init__(self, *args, **kwargs):
9+
super().__init__(*args, **kwargs)
10+
11+
self.fields["have_you_ever_smoked"] = TypedChoiceField(
12+
choices=HaveYouEverSmokedValues.choices,
13+
widget=forms.RadioSelect,
14+
label="Have you ever smoked?",
15+
label_classes="nhsuk-fieldset__legend--m",
16+
coerce=int
17+
)
18+
19+
class Meta:
20+
model = ResponseSet
21+
fields = ['have_you_ever_smoked']

lung_cancer_screening/questions/jinja2/have_you_ever_smoked.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<form action="{{ request.path }}" method="POST">
99
{{ csrf_input }}
1010

11-
{{ form.value.as_field_group() }}
11+
{{ form.have_you_ever_smoked.as_field_group() }}
1212

1313

1414
{{ button({

lung_cancer_screening/questions/jinja2/responses.jinja

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
<div class="nhsuk-grid-column-two-thirds">
77
<h1 class="nhsuk-heading-l">Responses</h1>
88
<ul class="responses">
9-
{% for response in responses %}
10-
<li>{{ response.question }} {{ response.value }}</li>
11-
{% endfor %}
9+
<li>Have you ever smoked? {{ response_set.get_have_you_ever_smoked_display() }}</li>
10+
<li>What is your date of birth? {{ response_set.date_of_birth }}</li>
1211
</ul>
1312
</div>
1413
</div>

lung_cancer_screening/questions/migrations/0003_booleanresponse_question_and_more.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Migration(migrations.Migration):
1313
migrations.AddField(
1414
model_name='BooleanResponse',
1515
name='question',
16-
field=models.CharField(null='Have you ever smoked?', max_length=255),
16+
field=models.CharField(default='Have you ever smoked?', max_length=255),
1717
preserve_default=False,
1818
),
1919
migrations.AddField(

0 commit comments

Comments
 (0)