Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions lung_cancer_screening/questions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,40 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.urls import path
from .views.start import start
from .views.have_you_ever_smoked import have_you_ever_smoked
from .views.date_of_birth import date_of_birth
from .views.responses import responses
from .views.start import StartView
from .views.have_you_ever_smoked import HaveYouEverSmokedView
from .views.date_of_birth import DateOfBirthView
from .views.responses import ResponsesView
from .views.age_range_exit import age_range_exit
from .views.non_smoker_exit import non_smoker_exit
from .views.your_results import your_results
from .views.height import height
from .views.weight import weight
from .views.sex_at_birth import sex_at_birth
from .views.gender import gender
from .views.ethnicity import ethnicity
from .views.height import HeightView
from .views.weight import WeightView
from .views.sex_at_birth import SexAtBirthView
from .views.gender import GenderView
from .views.ethnicity import EthnicityView
from .views.education import EducationView
from .views.respiratory_conditions import RespiratoryConditionsView
from .views.asbestos_exposure import AsbestosExposureView
from .views.cancer_diagnosis import CancerDiagnosisView
from .views.family_history_lung_cancer import FamilyHistoryLungCancerView


urlpatterns = [
path('start', start, name='start'),
path('have-you-ever-smoked', have_you_ever_smoked, name='have_you_ever_smoked'),
path('date-of-birth', date_of_birth, name='date_of_birth'),
path('height', height, name='height'),
path('weight', weight, name='weight'),
path('sex-at-birth', sex_at_birth, name='sex_at_birth'),
path('gender', gender, name='gender'),
path('ethnicity', ethnicity, name='ethnicity'),
path('start', StartView.as_view(), name='start'),
path('have-you-ever-smoked', HaveYouEverSmokedView.as_view(), name='have_you_ever_smoked'),
path('date-of-birth', DateOfBirthView.as_view(), name='date_of_birth'),
path('height', HeightView.as_view(), name='height'),
path('weight', WeightView.as_view(), name='weight'),
path('sex-at-birth', SexAtBirthView.as_view(), name='sex_at_birth'),
path('gender', GenderView.as_view(), name='gender'),
path('ethnicity', EthnicityView.as_view(), name='ethnicity'),
path('education', EducationView.as_view(), name='education'),
path('respiratory-conditions', RespiratoryConditionsView.as_view(), name='respiratory_conditions'),
path('asbestos-exposure', AsbestosExposureView.as_view(), name='asbestos_exposure'),
path('cancer-diagnosis', CancerDiagnosisView.as_view(), name='cancer_diagnosis'),
path('family-history-lung-cancer', FamilyHistoryLungCancerView.as_view(), name='family_history_lung_cancer'),
path('responses', responses, name='responses'),
path('responses', ResponsesView.as_view(), name='responses'),
path('age-range-exit', age_range_exit, name='age_range_exit'),
path('non-smoker-exit', non_smoker_exit, name='non_smoker_exit'),
path('your-results', your_results, name='your_results'),
Expand Down
21 changes: 11 additions & 10 deletions lung_cancer_screening/questions/views/date_of_birth.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views.decorators.http import require_http_methods
from django.views import View
from django.utils.decorators import method_decorator
from datetime import date
from dateutil.relativedelta import relativedelta

from .decorators.participant_decorators import require_participant
from ..forms.date_of_birth_form import DateOfBirthForm

@require_http_methods(["GET", "POST"])
@require_participant
def date_of_birth(request):
if request.method == "POST":
@method_decorator(require_participant, name="dispatch")
class DateOfBirthView(View):
def get(self, request):
return render_template(
request,
DateOfBirthForm(participant=request.participant)
)

def post(self, request):
form = DateOfBirthForm(
participant=request.participant,
data=request.POST
Expand All @@ -37,11 +43,6 @@ def date_of_birth(request):
status=422
)

return render_template(
request,
DateOfBirthForm(participant=request.participant)
)

def render_template(request, form, status=200):
return render(
request,
Expand Down
19 changes: 10 additions & 9 deletions lung_cancer_screening/questions/views/ethnicity.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views.decorators.http import require_http_methods
from django.views import View
from django.utils.decorators import method_decorator

from .decorators.participant_decorators import require_participant
from ..forms.ethnicity_form import EthnicityForm

@require_http_methods(["GET", "POST"])
@require_participant
def ethnicity(request):
@method_decorator(require_participant, name="dispatch")
class EthnicityView(View):
def get(self, request):
return render_template(
request,
EthnicityForm(participant=request.participant)
)

if request.method == "POST":
def post(self, request):
form = EthnicityForm(
participant=request.participant,
data=request.POST
Expand All @@ -27,10 +32,6 @@ def ethnicity(request):
status=422
)

return render_template(
request,
EthnicityForm(participant=request.participant)
)

def render_template(request, form, status=200):
return render(
Expand Down
21 changes: 11 additions & 10 deletions lung_cancer_screening/questions/views/gender.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views.decorators.http import require_http_methods
from django.views import View
from django.utils.decorators import method_decorator

from .decorators.participant_decorators import require_participant
from ..forms.gender_form import GenderForm

@require_http_methods(["GET", "POST"])
@require_participant
def gender(request):
if request.method == "POST":
@method_decorator(require_participant, name="dispatch")
class GenderView(View):
def get(self, request):
return render_template(
request,
GenderForm(participant=request.participant),
)

def post(self, request):
form = GenderForm(
participant=request.participant,
data=request.POST
Expand All @@ -26,11 +32,6 @@ def gender(request):
status=422
)

return render_template(
request,
GenderForm(participant=request.participant),
)

def render_template(request, form, status=200):
return render(
request,
Expand Down
23 changes: 12 additions & 11 deletions lung_cancer_screening/questions/views/have_you_ever_smoked.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views.decorators.http import require_http_methods
from django.views import View
from django.utils.decorators import method_decorator

from .decorators.participant_decorators import require_participant
from ..forms.have_you_ever_smoked_form import HaveYouEverSmokedForm
from ..models.response_set import HaveYouEverSmokedValues

@require_http_methods(["GET", "POST"])
@require_participant
def have_you_ever_smoked(request):
if request.method == "POST":
@method_decorator(require_participant, name="dispatch")
class HaveYouEverSmokedView(View):
def get(self, request):
return render_template(
request,
HaveYouEverSmokedForm(participant=request.participant)
)

def post(self, request):
form = HaveYouEverSmokedForm(
data=request.POST, participant=request.participant
)
Expand All @@ -30,15 +36,10 @@ def have_you_ever_smoked(request):
else:
return render_template(
request,
HaveYouEverSmokedForm(participant=request.participant),
form,
status=422
)

return render_template(
request,
HaveYouEverSmokedForm(participant=request.participant)
)


def render_template(request, form, status=200):
return render(
Expand Down
75 changes: 40 additions & 35 deletions lung_cancer_screening/questions/views/height.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
from django.shortcuts import render, redirect
from django.views.decorators.http import require_http_methods
from django.views import View
from django.utils.decorators import method_decorator

from lung_cancer_screening.questions.forms.metric_height_form import MetricHeightForm
from lung_cancer_screening.questions.forms.imperial_height_form import ImperialHeightForm
from .decorators.participant_decorators import require_participant

@require_http_methods(["GET", "POST"])
@require_participant
def height(request):
unit = request.GET.get('unit')
form_klass = ImperialHeightForm if unit == "imperial" else MetricHeightForm

if request.method == "POST":
form = form_klass(
instance = request.participant.responseset_set.last(),
data=request.POST,
participant=request.participant
@method_decorator(require_participant, name="dispatch")
class HeightView(View):
def get(self, request):
unit = request.GET.get('unit')
form_klass = ImperialHeightForm if unit == "imperial" else MetricHeightForm

return render(
request,
"height.jinja",
{
"form": form_klass(participant=request.participant),
"unit": unit,
"switch_to_unit": "metric" if unit == "imperial" else "imperial"
}
)

if form.is_valid():
form.save()

return redirect("questions:weight")
else:
return render(
request,
"height.jinja",
{
"form": form,
"unit": unit,
"switch_to_unit": "metric" if unit == "imperial" else "imperial"
},
status=422

def post(self, request):
unit = request.GET.get('unit')
form_klass = ImperialHeightForm if unit == "imperial" else MetricHeightForm

if request.method == "POST":
form = form_klass(
instance = request.participant.responseset_set.last(),
data=request.POST,
participant=request.participant
)

return render(
request,
"height.jinja",
{
"form": form_klass(participant=request.participant),
"unit": unit,
"switch_to_unit": "metric" if unit == "imperial" else "imperial"
}
)
if form.is_valid():
form.save()

return redirect("questions:weight")
else:
return render(
request,
"height.jinja",
{
"form": form,
"unit": unit,
"switch_to_unit": "metric" if unit == "imperial" else "imperial"
},
status=422
)
25 changes: 13 additions & 12 deletions lung_cancer_screening/questions/views/responses.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from django.shortcuts import render, redirect
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.http import require_http_methods
from django.views import View
from django.utils.decorators import method_decorator

from .decorators.participant_decorators import require_participant

@require_http_methods(["GET", "POST"])
@require_participant
def responses(request):
response_set = request.participant.responseset_set.last()
@method_decorator(require_participant, name="dispatch")
class ResponsesView(View):
def get(self, request):
return render(
request,
"responses.jinja",
{"response_set": request.participant.responseset_set.last()}
)

def post(self, request):
response_set = request.participant.responseset_set.last()

if request.method == "POST":
response_set.submitted_at = timezone.now()
response_set.save()

return redirect(reverse("questions:your_results"))

return render(
request,
"responses.jinja",
{"response_set": response_set}
)
20 changes: 11 additions & 9 deletions lung_cancer_screening/questions/views/sex_at_birth.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views.decorators.http import require_http_methods
from django.views import View
from django.utils.decorators import method_decorator

from .decorators.participant_decorators import require_participant
from ..forms.sex_at_birth_form import SexAtBirthForm

@require_http_methods(["GET", "POST"])
@require_participant
def sex_at_birth(request):
if request.method == "POST":
@method_decorator(require_participant, name="dispatch")
class SexAtBirthView(View):
def get(self, request):
return render_template(
request,
SexAtBirthForm(participant=request.participant)
)

def post(self, request):
form = SexAtBirthForm(
participant=request.participant,
data=request.POST
Expand All @@ -26,10 +32,6 @@ def sex_at_birth(request):
status=422
)

return render_template(
request,
SexAtBirthForm(participant=request.participant)
)

def render_template(request, form, status=200):
return render(
Expand Down
Loading
Loading