Skip to content

Commit 57149cc

Browse files
committed
Make CheckNeedAppointment use simpler view pattern
1 parent 056ad20 commit 57149cc

2 files changed

Lines changed: 21 additions & 41 deletions

File tree

features/check_need_appointment.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ Feature: Check if you need an appointment page
2727
When I check "No, I can continue online" and submit
2828
Then I am on "/height"
2929

30+
Scenario: Checking responses and changing them
31+
Given I am logged in
32+
When I go to "/check-if-you-need-an-appointment"
33+
And I check "No, I can continue online" and submit
34+
When I click "Back"
35+
Then I see "No, I can continue online" selected
3036

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,21 @@
1-
from django.shortcuts import render, redirect
2-
from django.urls import reverse
3-
from django.contrib.auth.mixins import LoginRequiredMixin
4-
from django.views import View
1+
from django.urls import reverse, reverse_lazy
52

6-
from .mixins.ensure_response_set import EnsureResponseSet
3+
from .question_base_view import QuestionBaseView
74
from ..forms.check_need_appointment_form import CheckNeedAppointmentForm
8-
from ..models.check_need_appointment_response import CheckNeedAppointmentResponse
5+
from ..models.check_need_appointment_response import (
6+
CheckNeedAppointmentResponse
7+
)
98

10-
class CheckNeedAppointmentView(LoginRequiredMixin, EnsureResponseSet, View):
11-
def get(self, request):
12-
response, _ = CheckNeedAppointmentResponse.objects.get_or_build(
13-
response_set=request.response_set
14-
)
159

16-
return render_template(request, CheckNeedAppointmentForm(instance=response))
10+
class CheckNeedAppointmentView(QuestionBaseView):
11+
template_name = "check_need_appointment.jinja"
12+
form_class = CheckNeedAppointmentForm
13+
model = CheckNeedAppointmentResponse
14+
success_url = reverse_lazy("questions:height")
15+
back_link_url = reverse_lazy("questions:date_of_birth")
1716

18-
def post(self, request):
19-
response, _ = CheckNeedAppointmentResponse.objects.get_or_build(
20-
response_set=request.response_set
21-
)
22-
form = CheckNeedAppointmentForm(
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-
31-
if form.cleaned_data["value"] :
32-
return redirect(reverse("questions:book_an_appointment"))
33-
else :
34-
return redirect(reverse("questions:height"))
17+
def get_success_url(self):
18+
if self.object.value:
19+
return reverse("questions:book_an_appointment")
3520
else:
36-
return render_template(request, form, 422)
37-
38-
def render_template(request, form, status=200):
39-
return render(
40-
request,
41-
"check_need_appointment.jinja",
42-
{
43-
"form": form,
44-
"back_link_url": reverse("questions:date_of_birth")
45-
},
46-
status=status
47-
)
21+
return super().get_success_url()

0 commit comments

Comments
 (0)