|
1 | | -from django.shortcuts import render |
2 | | -from django.urls import reverse |
| 1 | +from django.urls import reverse_lazy |
3 | 2 |
|
4 | 3 | from .question_base_view import QuestionBaseView |
5 | 4 | from ..forms.asbestos_exposure_form import AsbestosExposureForm |
6 | 5 | from ..models.asbestos_exposure_response import AsbestosExposureResponse |
7 | 6 |
|
8 | 7 | class AsbestosExposureView(QuestionBaseView): |
9 | | - def get(self, request): |
10 | | - response, _ = AsbestosExposureResponse.objects.get_or_build( |
11 | | - response_set=request.response_set |
12 | | - ) |
13 | | - return render_template( |
14 | | - request, |
15 | | - AsbestosExposureForm(instance=response) |
16 | | - ) |
17 | | - |
18 | | - def post(self, request): |
19 | | - response, _ = AsbestosExposureResponse.objects.get_or_build( |
20 | | - response_set=request.response_set |
21 | | - ) |
22 | | - form = AsbestosExposureForm( |
23 | | - instance=response, |
24 | | - data=request.POST |
25 | | - ) |
26 | | - |
27 | | - if form.is_valid(): |
28 | | - response.value = form.cleaned_data["value"] |
29 | | - response.save() |
30 | | - return self.redirect_to_response_or_next_question( |
31 | | - request, |
32 | | - "questions:cancer_diagnosis" |
33 | | - ) |
34 | | - else: |
35 | | - return render_template(request, form, 422) |
36 | | - |
37 | | -def render_template(request, form, status=200): |
38 | | - return render( |
39 | | - request, |
40 | | - "asbestos_exposure.jinja", |
41 | | - { |
42 | | - "form": form, |
43 | | - "back_link_url": reverse("questions:respiratory_conditions") |
44 | | - }, |
45 | | - status=status |
46 | | - ) |
| 8 | + template_name = "asbestos_exposure.jinja" |
| 9 | + form_class = AsbestosExposureForm |
| 10 | + model = AsbestosExposureResponse |
| 11 | + success_url = reverse_lazy("questions:cancer_diagnosis") |
| 12 | + back_link_url = reverse_lazy("questions:respiratory_conditions") |
0 commit comments