diff --git a/features/environment.py b/features/environment.py index 670e106b..4c8b79a4 100644 --- a/features/environment.py +++ b/features/environment.py @@ -27,6 +27,7 @@ def setUpClass(cls): def before_all(context): """Set up before all tests run.""" # Set up live server (behave-django handles test database) + os.system('rm screenshots/*') LiveServer.setUpClass() context.live_server_url = LiveServer.live_server_url context.live_server_class = LiveServer diff --git a/features/questionnaire.feature b/features/questionnaire.feature index 5e4b9cc5..78fcf942 100644 --- a/features/questionnaire.feature +++ b/features/questionnaire.feature @@ -1,4 +1,3 @@ -@AgeWhenStartedSmoking Feature: Questionnaire Scenario: Cannot change responses once submitted Given I am logged in @@ -59,7 +58,6 @@ Feature: Questionnaire Then I am on "/age-when-started-smoking" When I fill in "How old were you when you started smoking?" as "18" and submit - Then I am on "/periods-when-you-stopped-smoking" When I check "Yes" And I fill in "Enter the total number of years you stopped smoking for" with "10" @@ -70,6 +68,9 @@ Feature: Questionnaire And I check "Pipe" And I submit the form + Then I am on "/cigarettes-smoking-current" + When I check "Yes" and submit + Then I am on "/cigarettes-smoked-total-years" When I fill in "Roughly how many years have you smoked cigarettes?" with "10" And I submit the form diff --git a/features/smoking_current.feature b/features/smoking_current.feature new file mode 100644 index 00000000..ae4c6c92 --- /dev/null +++ b/features/smoking_current.feature @@ -0,0 +1,43 @@ +@SmokingCurrent +Feature: Smoking current page + Scenario: The page is accessible + Given I am logged in + And I have answered questions showing I am eligible + When I go to "/cigarettes-smoking-current" + Then there are no accessibility violations + + Scenario: Form errors + Given I am logged in + And I have answered questions showing I am eligible + When I go to "/cigarettes-smoking-current" + And I click "Continue" + Then I am on "/cigarettes-smoking-current" + And I see a form error "Select if you currently smoke cigarettes" + And there are no accessibility violations + + Scenario: Navigating backwards and forwards + Given I am logged in + And I have answered questions showing I am eligible + And I have answered questions showing I have smoked for "10" years + And I have answered questions showing I have smoked "Cigarettes" + When I go to "/cigarettes-smoking-current" + Then I see a back link to "/age-when-started-smoking" + When I check "Yes" and submit + Then I am on "/cigarettes-smoked-total-years" + + Scenario: Checking responses and changing them + Given I am logged in + And I have answered questions showing I am eligible + And I have answered questions showing I have smoked for "10" years + And I have answered questions showing I have smoked "Cigarettes" + When I go to "/cigarettes-smoking-current" + When I check "Yes" and submit + When I go to "/check-your-answers" + Then I see "Yes" as a response to "Do you currently smoke cigarettes?" under "Smoking history" + And I see "/cigarettes-smoking-current?change=True" as a link to change "Do you currently smoke cigarettes?" under "Smoking history" + When I click the link to change "Do you currently smoke cigarettes?" under "Smoking history" + Then I am on "/cigarettes-smoking-current?change=True" + And I see "Yes" selected + When I check "No" and submit + Then I am on "/check-your-answers" + And I see "No" as a response to "Do you currently smoke cigarettes?" under "Smoking history" diff --git a/features/types_tobacco_smoking.feature b/features/types_tobacco_smoking.feature index f03e5cba..a4ef7540 100644 --- a/features/types_tobacco_smoking.feature +++ b/features/types_tobacco_smoking.feature @@ -25,7 +25,7 @@ Feature: Types tobacco smoking page Then I see a back link to "/periods-when-you-stopped-smoking" When I check "Cigarettes" And I submit the form - Then I am on "/cigarettes-smoked-total-years" + Then I am on "/cigarettes-smoking-current" Scenario: Checking responses and changing them Given I am logged in @@ -45,6 +45,6 @@ Feature: Types tobacco smoking page And I see "Cigars" selected When I check "Pipe" And I click "Continue" - Then I am on "/cigarettes-smoked-total-years" + Then I am on "/cigarettes-smoking-current" When I go to "/check-your-answers" Then I see "Cigarettes, Pipe, and Cigars" as a response to "Types of tobacco smoked" under "Smoking history" diff --git a/lung_cancer_screening/questions/forms/smoking_current_form.py b/lung_cancer_screening/questions/forms/smoking_current_form.py new file mode 100644 index 00000000..19f8161a --- /dev/null +++ b/lung_cancer_screening/questions/forms/smoking_current_form.py @@ -0,0 +1,25 @@ +from django import forms + +from ..models import SmokingCurrentResponse + +from ...nhsuk_forms.typed_choice_field import TypedChoiceField + +class SmokingCurrentForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.fields["value"] = TypedChoiceField( + choices=[(True, 'Yes'), (False, 'No')], + widget=forms.RadioSelect, + label="Do you currently smoke cigarettes?", + label_classes="nhsuk-fieldset__legend--l", + label_is_page_heading=True, + coerce=lambda x: x == 'True', + error_messages={ + 'required': 'Select if you currently smoke cigarettes', + } + ) + + class Meta: + model = SmokingCurrentResponse + fields = ['value'] diff --git a/lung_cancer_screening/questions/migrations/0051_smokingcurrentresponse.py b/lung_cancer_screening/questions/migrations/0051_smokingcurrentresponse.py new file mode 100644 index 00000000..240ec805 --- /dev/null +++ b/lung_cancer_screening/questions/migrations/0051_smokingcurrentresponse.py @@ -0,0 +1,27 @@ +# Generated by Django 5.2.11 on 2026-02-04 13:59 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('questions', '0050_alter_periodswhenyoustoppedsmokingresponse_duration_years_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='SmokingCurrentResponse', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('value', models.BooleanField()), + ('tobacco_smoking_history', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='smoking_current_response', to='questions.tobaccosmokinghistory')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/lung_cancer_screening/questions/models/__init__.py b/lung_cancer_screening/questions/models/__init__.py index 6c3ef225..bd7ab999 100644 --- a/lung_cancer_screening/questions/models/__init__.py +++ b/lung_cancer_screening/questions/models/__init__.py @@ -16,5 +16,6 @@ from .relatives_age_when_diagnosed_response import RelativesAgeWhenDiagnosedResponse # noqa: F401 from .respiratory_conditions_response import RespiratoryConditionsResponse # noqa: F401 from .sex_at_birth_response import SexAtBirthResponse # noqa: F401 +from .smoking_current_response import SmokingCurrentResponse # noqa: F401 from .tobacco_smoking_history import TobaccoSmokingHistory # noqa: F401 from .weight_response import WeightResponse # noqa: F401 diff --git a/lung_cancer_screening/questions/models/smoking_current_response.py b/lung_cancer_screening/questions/models/smoking_current_response.py new file mode 100644 index 00000000..41030d51 --- /dev/null +++ b/lung_cancer_screening/questions/models/smoking_current_response.py @@ -0,0 +1,12 @@ +from django.db import models + +from .base import BaseModel +from .tobacco_smoking_history import TobaccoSmokingHistory + +class SmokingCurrentResponse(BaseModel): + tobacco_smoking_history = models.OneToOneField( + TobaccoSmokingHistory, + on_delete=models.CASCADE, + related_name='smoking_current_response') + + value = models.BooleanField() diff --git a/lung_cancer_screening/questions/presenters/response_set_presenter.py b/lung_cancer_screening/questions/presenters/response_set_presenter.py index c65bf3c7..c485ccfb 100644 --- a/lung_cancer_screening/questions/presenters/response_set_presenter.py +++ b/lung_cancer_screening/questions/presenters/response_set_presenter.py @@ -251,15 +251,25 @@ def family_history_responses_items(self): def smoking_history_types_responses_items(self): - return [*[ - self._check_your_answer_item( + results = [] + for type_history in self.response_set.tobacco_smoking_history.in_form_order(): + results.extend(self.smoking_history_summary_items_for_type(type_history)) + return results + + def smoking_history_summary_items_for_type(self, type_history): + return [self._check_your_answer_item( + f"Do you currently smoke {type_history.human_type().lower()}?", + self._boolean_response_to_yes_no(type_history, "smoking_current_response"), + "questions:smoking_current", + kwargs = { "tobacco_type": humps.kebabize(type_history.type) } + ), + (self._check_your_answer_item( f"Total number of years you have smoked {type_history.human_type().lower()}", - type_history.smoked_total_years_response.value if hasattr(type_history, 'smoked_total_years_response') else None, + type_history.smoked_total_years_response.value if hasattr(type_history, 'smoked_total_years_response') else self.NOT_ANSWERED_TEXT, "questions:smoked_total_years", - kwargs = { "tobacco_type": humps.kebabize(type_history.type) }, - ) - for type_history in self.response_set.tobacco_smoking_history.in_form_order() - ]] + kwargs = { "tobacco_type": humps.kebabize(type_history.type) } + ))] + def smoking_history_responses_items(self): return [ @@ -278,7 +288,7 @@ def smoking_history_responses_items(self): self.types_tobacco_smoking, "questions:types_tobacco_smoking", ), - *self.smoking_history_types_responses_items() + *self.smoking_history_types_responses_items(), ] @@ -321,3 +331,13 @@ def _check_your_answer_item(self, question, value, url_lookup_name, kwargs = {}) ] } } + + def _boolean_response_to_yes_no(self, response, attribute_name, yes_text = "Yes", no_text = "No"): + if hasattr(response, attribute_name): + result = getattr(response, attribute_name) + if result is True: + return yes_text + elif result is False: + return no_text + else: + return self.NOT_ANSWERED_TEXT diff --git a/lung_cancer_screening/questions/tests/factories/smoking_current_response_factory.py b/lung_cancer_screening/questions/tests/factories/smoking_current_response_factory.py new file mode 100644 index 00000000..29c2504c --- /dev/null +++ b/lung_cancer_screening/questions/tests/factories/smoking_current_response_factory.py @@ -0,0 +1,13 @@ +import factory + +from .tobacco_smoking_history_factory import TobaccoSmokingHistoryFactory + +from ...models import SmokingCurrentResponse + + +class SmokingCurrentResponseFactory(factory.django.DjangoModelFactory): + class Meta: + model = SmokingCurrentResponse + + tobacco_smoking_history = factory.SubFactory(TobaccoSmokingHistoryFactory) + value = factory.Faker('boolean') diff --git a/lung_cancer_screening/questions/tests/unit/forms/test_smoking_current_form.py b/lung_cancer_screening/questions/tests/unit/forms/test_smoking_current_form.py new file mode 100644 index 00000000..26d446f9 --- /dev/null +++ b/lung_cancer_screening/questions/tests/unit/forms/test_smoking_current_form.py @@ -0,0 +1,59 @@ +from django.test import TestCase, tag + +from ....models.tobacco_smoking_history import TobaccoSmokingHistoryTypes +from ...factories.tobacco_smoking_history_factory import TobaccoSmokingHistoryFactory + +from ....models.smoking_current_response import SmokingCurrentResponse +from ....forms.smoking_current_form import SmokingCurrentForm + + +@tag("SmokingCurrent") +class TestSmokingCurrentForm(TestCase): + def setUp(self): + self.smoking_history = TobaccoSmokingHistoryFactory.create( + type=TobaccoSmokingHistoryTypes.CIGARETTES.value + ) + self.response = SmokingCurrentResponse.objects.create( + tobacco_smoking_history=self.smoking_history, + value=False + ) + + + def test_is_valid_with_a_valid_value(self): + form = SmokingCurrentForm( + instance=self.response, + data={ + "value": False + } + ) + self.assertTrue(form.is_valid()) + self.assertEqual( + form.cleaned_data["value"], + False + ) + + def test_is_invalid_with_an_invalid_value(self): + form = SmokingCurrentForm( + instance=self.response, + data={ + "value": "invalid" + } + ) + self.assertFalse(form.is_valid()) + self.assertEqual( + form.errors["value"], + ["Select a valid choice. invalid is not one of the available choices."] + ) + + def test_is_invalid_when_no_option_is_selected(self): + form = SmokingCurrentForm( + instance=self.response, + data={ + "value": None + } + ) + self.assertFalse(form.is_valid()) + self.assertEqual( + form.errors["value"], + ["Select if you currently smoke cigarettes"] + ) diff --git a/lung_cancer_screening/questions/tests/unit/models/test_periods_when_you_stopped_smoking_response.py b/lung_cancer_screening/questions/tests/unit/models/test_periods_when_you_stopped_smoking_response.py index b3f1f12f..0b28c79d 100644 --- a/lung_cancer_screening/questions/tests/unit/models/test_periods_when_you_stopped_smoking_response.py +++ b/lung_cancer_screening/questions/tests/unit/models/test_periods_when_you_stopped_smoking_response.py @@ -65,8 +65,6 @@ def test_is_invalid_if_duration_years_not_set_and_value_is_true(self): "Enter the total number of years you stopped smoking for" ) - - @tag("wip") def test_is_invalid_if_duration_years_is_less_than_1(self): response = PeriodsWhenYouStoppedSmokingResponse( response_set=self.response_set, diff --git a/lung_cancer_screening/questions/tests/unit/models/test_smoking_current_response.py b/lung_cancer_screening/questions/tests/unit/models/test_smoking_current_response.py new file mode 100644 index 00000000..d1d95694 --- /dev/null +++ b/lung_cancer_screening/questions/tests/unit/models/test_smoking_current_response.py @@ -0,0 +1,33 @@ +from django.test import TestCase, tag + +from lung_cancer_screening.questions.tests.factories.tobacco_smoking_history_factory import TobaccoSmokingHistoryFactory + +from ....models.smoking_current_response import SmokingCurrentResponse + +from ...factories.smoking_current_response_factory import SmokingCurrentResponseFactory + +@tag("SmokingCurrent") +class TestSmokingCurrentResponse(TestCase): + def setUp(self): + self.tobacco_smoking_history = TobaccoSmokingHistoryFactory() + + def test_has_a_valid_factory(self): + model = SmokingCurrentResponseFactory.build(tobacco_smoking_history=self.tobacco_smoking_history) + model.full_clean() + + + def test_has_response_set_as_foreign_key(self): + response = SmokingCurrentResponse.objects.create( + tobacco_smoking_history=self.tobacco_smoking_history, + value=True + ) + + self.assertEqual(response.tobacco_smoking_history, self.tobacco_smoking_history) + + def test_has_value_as_bool(self): + response = SmokingCurrentResponse.objects.create( + tobacco_smoking_history=self.tobacco_smoking_history, + value=False + ) + + self.assertIsInstance(response.value, bool) diff --git a/lung_cancer_screening/questions/tests/unit/presenters/test_response_set_presenter.py b/lung_cancer_screening/questions/tests/unit/presenters/test_response_set_presenter.py index 1bc5f594..ec33937d 100644 --- a/lung_cancer_screening/questions/tests/unit/presenters/test_response_set_presenter.py +++ b/lung_cancer_screening/questions/tests/unit/presenters/test_response_set_presenter.py @@ -436,7 +436,6 @@ def test_types_tobacco_smoking(self): presenter = ResponseSetPresenter(self.response_set) self.assertEqual(presenter.types_tobacco_smoking, "Cigarettes, Cigars, and Shisha") - def test_smoking_history_types_responses_items_sets_the_correct_key(self): TobaccoSmokingHistoryFactory.create( response_set=self.response_set, @@ -446,7 +445,7 @@ def test_smoking_history_types_responses_items_sets_the_correct_key(self): presenter = ResponseSetPresenter(self.response_set) response_items = presenter.smoking_history_types_responses_items() - cigarettes_response_item = response_items[0] + cigarettes_response_item = response_items[1] self.assertEqual( cigarettes_response_item.get("key").get("text"), @@ -469,7 +468,7 @@ def test_smoking_history_types_responses_items_sets_the_correct_value(self): presenter = ResponseSetPresenter(self.response_set) response_items = presenter.smoking_history_types_responses_items() - cigarettes_response_item = response_items[0] + cigarettes_response_item = response_items[1] self.assertEqual( cigarettes_response_item.get("value").get("text"), @@ -485,7 +484,7 @@ def test_smoking_history_types_responses_items_sets_the_correct_change_link(self presenter = ResponseSetPresenter(self.response_set) response_items = presenter.smoking_history_types_responses_items() - cigarettes_response_item = response_items[0] + cigarettes_response_item = response_items[1] self.assertEqual( cigarettes_response_item.get("actions").get("items")[0].get("href"), diff --git a/lung_cancer_screening/questions/tests/unit/views/test_smoking_current.py b/lung_cancer_screening/questions/tests/unit/views/test_smoking_current.py new file mode 100644 index 00000000..5ae6002e --- /dev/null +++ b/lung_cancer_screening/questions/tests/unit/views/test_smoking_current.py @@ -0,0 +1,171 @@ +import humps + +from django.test import TestCase, tag +from django.urls import reverse + +from lung_cancer_screening.questions.models.tobacco_smoking_history import TobaccoSmokingHistoryTypes +from lung_cancer_screening.questions.tests.factories.tobacco_smoking_history_factory import TobaccoSmokingHistoryFactory + +from .helpers.authentication import login_user +from ...factories.response_set_factory import ResponseSetFactory + + +@tag("SmokingCurrent") +class TestGetSmokingCurrent(TestCase): + def setUp(self): + self.user = login_user(self.client) + self.response_set = ResponseSetFactory.create(user=self.user, eligible=True) + self.tobacco_smoking_history = TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + type=TobaccoSmokingHistoryTypes.CIGARETTES.value + ) + + + def test_redirects_if_the_user_is_not_logged_in(self): + self.client.logout() + + response = self.client.get( + reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + }) + ) + + self.assertRedirects(response, "/oidc/authenticate/?next=/cigarettes-smoking-current", fetch_redirect_response=False) + + + def test_redirects_when_a_submitted_response_set_exists_within_the_last_year(self): + self.response_set.delete() + ResponseSetFactory.create( + user=self.user, + recently_submitted=True + ) + + response = self.client.get( + reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + }) + ) + + self.assertRedirects(response, reverse("questions:confirmation")) + + + def test_redirects_when_the_user_is_not_eligible(self): + self.response_set.delete() + ResponseSetFactory.create(user=self.user, eligible=False) + + response = self.client.get( + reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + }) + ) + + self.assertRedirects(response, reverse("questions:have_you_ever_smoked")) + + + def test_responds_successfully(self): + response = self.client.get(reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + })) + + self.assertEqual(response.status_code, 200) + + +@tag("SmokingCurrent") +class TestPostSmokingCurrent(TestCase): + def setUp(self): + self.user = login_user(self.client) + self.response_set = ResponseSetFactory.create(user=self.user, eligible=True) + self.tobacco_smoking_history = TobaccoSmokingHistoryFactory.create( + response_set=self.response_set, + type=TobaccoSmokingHistoryTypes.CIGARETTES.value + ) + + self.valid_params = {"value": True} + + + def test_redirects_if_the_user_is_not_logged_in(self): + self.client.logout() + + response = self.client.post( + reverse("questions:smoking_current", kwargs={"tobacco_type": "cigarettes"}), + self.valid_params + ) + + self.assertRedirects(response, "/oidc/authenticate/?next=/cigarettes-smoking-current", fetch_redirect_response=False) + + + def test_redirects_when_a_submitted_response_set_exists_within_the_last_year(self): + self.response_set.delete() + ResponseSetFactory.create( + user=self.user, + recently_submitted=True + ) + + response = self.client.post( + reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + }), + self.valid_params + ) + + self.assertRedirects(response, reverse("questions:confirmation")) + + + def test_redirects_when_the_user_is_not_eligible(self): + self.response_set.delete() + ResponseSetFactory.create(user=self.user, eligible=False) + + response = self.client.post( + reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + }), + self.valid_params + ) + + self.assertRedirects(response, reverse("questions:have_you_ever_smoked")) + + def test_creates_a_smoking_current_response(self): + self.client.post(reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + }), self.valid_params) + + self.tobacco_smoking_history.refresh_from_db() + self.assertEqual( + self.tobacco_smoking_history.smoking_current_response.value, self.valid_params["value"] + ) + + def test_redirects_to_next_question(self): + response = self.client.post( + reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + }), + self.valid_params + ) + + self.assertRedirects(response, reverse("questions:smoked_total_years", kwargs={ + "tobacco_type": humps.kebabize(TobaccoSmokingHistoryTypes.CIGARETTES.value) + }), fetch_redirect_response=False) + + def test_redirects_to_responses_if_change_query_param_is_true(self): + response = self.client.post( + reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + }), + { + **self.valid_params, + "change": "True" + } + ) + + self.assertRedirects(response, reverse("questions:responses")) + + + def test_responds_with_422_if_the_response_fails_to_create(self): + response = self.client.post( + reverse("questions:smoking_current", kwargs = { + "tobacco_type": TobaccoSmokingHistoryTypes.CIGARETTES.value.lower() + }), + {"value": "something not in list"} + ) + + self.assertEqual(response.status_code, 422) diff --git a/lung_cancer_screening/questions/tests/unit/views/test_types_tobacco_smoking.py b/lung_cancer_screening/questions/tests/unit/views/test_types_tobacco_smoking.py index d34b95ce..91f532cf 100644 --- a/lung_cancer_screening/questions/tests/unit/views/test_types_tobacco_smoking.py +++ b/lung_cancer_screening/questions/tests/unit/views/test_types_tobacco_smoking.py @@ -126,6 +126,6 @@ def test_post_redirects_to_the_first_type_of_tobacco_smoking_history_question(se self.valid_params ) - self.assertRedirects(response, reverse("questions:smoked_total_years", kwargs={ + self.assertRedirects(response, reverse("questions:smoking_current", kwargs={ "tobacco_type": humps.kebabize(TobaccoSmokingHistoryTypes.CIGARETTES.value) }), fetch_redirect_response=False) diff --git a/lung_cancer_screening/questions/urls.py b/lung_cancer_screening/questions/urls.py index 43616c6b..fef862a9 100644 --- a/lung_cancer_screening/questions/urls.py +++ b/lung_cancer_screening/questions/urls.py @@ -37,6 +37,7 @@ from .views.responses import ResponsesView from .views.sex_at_birth import SexAtBirthView from .views.types_tobacco_smoking import TypesTobaccoSmokingView +from .views.smoking_current import SmokingCurrentView from .views.smoked_total_years import SmokedTotalYearsView from .views.start import StartView from .views.weight import WeightView @@ -51,6 +52,7 @@ path('call-us-to-book-an-appointment', BookAnAppointmentExitView.as_view(), name='book_an_appointment'), path('cancer-diagnosis', CancerDiagnosisView.as_view(), name='cancer_diagnosis'), path('check-if-you-need-an-appointment', CheckNeedAppointmentView.as_view(), name='check_need_appointment'), + path('-smoking-current', SmokingCurrentView.as_view(), name='smoking_current'), path('date-of-birth', DateOfBirthView.as_view(), name='date_of_birth'), path('education', EducationView.as_view(), name='education'), path('ethnicity', EthnicityView.as_view(), name='ethnicity'), diff --git a/lung_cancer_screening/questions/views/smoking_current.py b/lung_cancer_screening/questions/views/smoking_current.py new file mode 100644 index 00000000..0ad7c031 --- /dev/null +++ b/lung_cancer_screening/questions/views/smoking_current.py @@ -0,0 +1,19 @@ +from django.urls import reverse_lazy +from django.contrib.auth.mixins import LoginRequiredMixin + +from lung_cancer_screening.questions.views.smoking_history_question_base_view import SmokingHistoryQuestionBaseView + +from .mixins.ensure_response_set import EnsureResponseSet +from .mixins.ensure_eligible import EnsureEligibleMixin +from ..forms.smoking_current_form import SmokingCurrentForm +from ..models.smoking_current_response import SmokingCurrentResponse + + +class SmokingCurrentView(LoginRequiredMixin, EnsureResponseSet, EnsureEligibleMixin, SmokingHistoryQuestionBaseView): + template_name = "question_form.jinja" + form_class = SmokingCurrentForm + model = SmokingCurrentResponse + success_url = reverse_lazy("questions:smoked_total_years", kwargs={ + "tobacco_type": "cigarettes" + }) + back_link_url = reverse_lazy("questions:age_when_started_smoking") diff --git a/lung_cancer_screening/questions/views/types_tobacco_smoking.py b/lung_cancer_screening/questions/views/types_tobacco_smoking.py index d1327c7f..bcbecb22 100644 --- a/lung_cancer_screening/questions/views/types_tobacco_smoking.py +++ b/lung_cancer_screening/questions/views/types_tobacco_smoking.py @@ -33,7 +33,7 @@ def form_valid(self, form): def get_success_url(self): return reverse( - "questions:smoked_total_years", + "questions:smoking_current", kwargs={ "tobacco_type": humps.kebabize( self.request.response_set.tobacco_smoking_history.first().type