Skip to content

Commit

Permalink
refactor(views): integrate verifier selection form into flow
Browse files Browse the repository at this point in the history
Make eligibility index handle the EligibilityVerifierSelectionForm, and
remove previous hard-coded logic in core/views.py for setting the
verifier.
  • Loading branch information
angela-tran committed Mar 22, 2022
1 parent a5a6981 commit 7a31ad9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 118 deletions.
2 changes: 1 addition & 1 deletion benefits/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def index(request):
def agency_index(request, agency):
"""View handler for an agency entry page."""
session.reset(request)
session.update(request, agency=agency, verifier=agency.eligibility_verifiers.all()[0], origin=agency.index_url)
session.update(request, agency=agency, origin=agency.index_url)

page = viewmodels.Page(
content_title=_index_content_title(),
Expand Down
50 changes: 28 additions & 22 deletions benefits/eligibility/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,44 @@
from django.utils.translation import pgettext, gettext as _

from benefits.core import middleware, recaptcha, session, viewmodels
from benefits.core.models import EligibilityVerifier
from benefits.core.views import PageTemplateResponse, _index_image
from . import analytics, api, forms


@decorator_from_middleware(middleware.AgencySessionRequired)
@decorator_from_middleware(middleware.VerifierSessionRequired)
def index(request):
"""View handler for the eligibility verification getting started screen."""
"""View handler for the eligibility verifier selection form."""

session.update(request, eligibility_types=[], origin=reverse("eligibility:index"))
agency = session.agency(request)

page = viewmodels.Page(
title=_("eligibility.pages.index.title"),
content_title=_("eligibility.pages.index.content_title"),
media=[
viewmodels.MediaItem(
icon=viewmodels.Icon("idcardcheck", pgettext("image alt text", "core.icons.idcardcheck")),
heading=_("eligibility.pages.index.items[0].title"),
details=_("eligibility.pages.index.items[0].text"),
),
viewmodels.MediaItem(
icon=viewmodels.Icon("bankcardcheck", pgettext("image alt text", "core.icons.bankcardcheck")),
heading=_("eligibility.pages.index.items[1].title"),
details=_("eligibility.pages.index.items[1].text"),
),
],
paragraphs=[_("eligibility.pages.index.p[0]")],
image=_index_image(),
button=viewmodels.Button.primary(text=_("eligibility.pages.index.button"), url=reverse("eligibility:confirm")),
)
eligibility_start = reverse("eligibility:start")

return PageTemplateResponse(request, page)
if request.method == "POST":
form = forms.EligibilityVerifierSelectionForm(data=request.POST, agency=agency)

if not form.is_valid():
return None

verifier_id = form.cleaned_data.get("verifier")
verifier = EligibilityVerifier.objects.get(id=verifier_id)
session.update(request, verifier=verifier)

return redirect(eligibility_start)
else:
if agency.eligibility_verifiers.count() == 1:
verifier = agency.eligibility_verifiers.first()
session.update(request, verifier=verifier)
return redirect(eligibility_start)
else:
page = viewmodels.Page(
title=_("eligibility.pages.index.title"),
content_title=_("eligibility.pages.index.content_title"),
forms=forms.EligibilityVerifierSelectionForm(agency=agency),
image=_index_image(),
)
return PageTemplateResponse(request, page)


@decorator_from_middleware(middleware.AgencySessionRequired)
Expand Down
65 changes: 18 additions & 47 deletions benefits/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: https://github.com/cal-itp/benefits/issues\n"
"POT-Creation-Date: 2022-03-22 20:00+0000\n"
"POT-Creation-Date: 2022-03-22 20:45+0000\n"
"Language: English\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -259,54 +259,25 @@ msgstr "Check your input. The format looks wrong."
msgid "eligibility.forms.confirm.errors.missing"
msgstr "This field is required."

#: benefits/eligibility/views.py:23
#: benefits/eligibility/views.py:38
msgid "eligibility.pages.index.title"
msgstr "Getting started"

#: benefits/eligibility/views.py:24
#: benefits/eligibility/views.py:39
msgid "eligibility.pages.index.content_title"
msgstr "Great, you’ll need two things before we get started..."
msgstr "Select the discount option that best applies to you:"

#: benefits/eligibility/views.py:27 benefits/eligibility/views.py:57
#: benefits/enrollment/views.py:31
#: benefits/eligibility/views.py:59 benefits/enrollment/views.py:31
msgctxt "image alt text"
msgid "core.icons.idcardcheck"
msgstr "Identification card icon with checkmark"

#: benefits/eligibility/views.py:28
msgid "eligibility.pages.index.items[0].title"
msgstr "Your California ID"

#: benefits/eligibility/views.py:29
msgid "eligibility.pages.index.items[0].text"
msgstr "Driver’s license or ID card"

#: benefits/eligibility/views.py:32 benefits/eligibility/views.py:62
#: benefits/enrollment/views.py:148
#: benefits/eligibility/views.py:64 benefits/enrollment/views.py:148
msgctxt "image alt text"
msgid "core.icons.bankcardcheck"
msgstr "Bank card icon with contactless symbol and checkmark"

#: benefits/eligibility/views.py:33
msgid "eligibility.pages.index.items[1].title"
msgstr "Your bank card"

#: benefits/eligibility/views.py:34
msgid "eligibility.pages.index.items[1].text"
msgstr "A debit or credit card"

#: benefits/eligibility/views.py:37
msgid "eligibility.pages.index.p[0]"
msgstr ""
"This program is currently open to those who are 65 or older. Not over 65? "
"Get in touch with your transit provider to learn about other available "
"discount programs."

#: benefits/eligibility/views.py:39
msgid "eligibility.pages.index.button"
msgstr "Ready to continue"

#: benefits/eligibility/views.py:53
#: benefits/eligibility/views.py:55
msgid "eligibility.pages.start.title"
msgstr "Getting started"

Expand All @@ -322,11 +293,11 @@ msgstr "Your California ID"
msgid "eligibility.pages.start.items[0].text"
msgstr "Driver’s license or ID card"

#: benefits/eligibility/views.py:63
#: benefits/eligibility/views.py:65
msgid "eligibility.pages.start.items[1].title"
msgstr "Your bank card"

#: benefits/eligibility/views.py:64
#: benefits/eligibility/views.py:66
msgid "eligibility.pages.start.items[1].text"
msgstr "A debit or credit card"

Expand All @@ -337,44 +308,44 @@ msgstr ""
"Get in touch with your transit provider to learn about other available "
"discount programs."

#: benefits/eligibility/views.py:69
#: benefits/eligibility/views.py:71
msgid "eligibility.pages.start.button"
msgstr "Ready to continue"

#: benefits/eligibility/views.py:82
#: benefits/eligibility/views.py:84
msgid "eligibility.pages.confirm.title"
msgstr "Confirm your age"

#: benefits/eligibility/views.py:83
#: benefits/eligibility/views.py:85
msgid "eligibility.pages.confirm.content_title"
msgstr "Let’s see if we can confirm your age with the DMV"

#: benefits/eligibility/views.py:84
#: benefits/eligibility/views.py:86
msgid "eligibility.pages.confirm.p[0]"
msgstr ""
"If you’re 65 or older, we can confirm you are eligible for a senior discount "
"when you ride transit. We don’t save your information."

#: benefits/eligibility/views.py:157
#: benefits/eligibility/views.py:159
msgid "eligibility.pages.unverified.title"
msgstr "Age not confirmed"

#: benefits/eligibility/views.py:158
#: benefits/eligibility/views.py:160
msgid "eligibility.pages.unverified.content_title"
msgstr "We can’t confirm your age"

#: benefits/eligibility/views.py:159
#: benefits/eligibility/views.py:161
msgctxt "image alt text"
msgid "core.icons.idcardquestion"
msgstr "Identification card icon with question mark"

#: benefits/eligibility/views.py:160
#: benefits/eligibility/views.py:162
msgid "eligibility.pages.unverified.p[0]"
msgstr ""
"You may still be eligible for a discount, but we can’t verify your age with "
"the DMV."

#: benefits/eligibility/views.py:160
#: benefits/eligibility/views.py:162
msgid "eligibility.pages.unverified.p[1]"
msgstr "Reach out to your transit provider for assistance."

Expand Down
66 changes: 18 additions & 48 deletions benefits/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: https://github.com/cal-itp/benefits/issues\n"
"POT-Creation-Date: 2022-03-22 20:00+0000\n"
"POT-Creation-Date: 2022-03-22 20:45+0000\n"
"Language: Español\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -261,56 +261,26 @@ msgstr "Verifique su entrada. El formato parece incorrecto."
msgid "eligibility.forms.confirm.errors.missing"
msgstr "Este campo es requerido."

#: benefits/eligibility/views.py:23
#: benefits/eligibility/views.py:38
msgid "eligibility.pages.index.title"
msgstr "Preparación"

#: benefits/eligibility/views.py:24
#: benefits/eligibility/views.py:39
msgid "eligibility.pages.index.content_title"
msgstr "Genial, necesitarás dos cosas antes de comenzar..."
msgstr "TODO"

#: benefits/eligibility/views.py:27 benefits/eligibility/views.py:57
#: benefits/enrollment/views.py:31
#: benefits/eligibility/views.py:59 benefits/enrollment/views.py:31
msgctxt "image alt text"
msgid "core.icons.idcardcheck"
msgstr "Icono de tarjeta de identificación con marca de verificación"

#: benefits/eligibility/views.py:28
msgid "eligibility.pages.index.items[0].title"
msgstr "Tu identificación de California"

#: benefits/eligibility/views.py:29
msgid "eligibility.pages.index.items[0].text"
msgstr "Licencia de conducir o tarjeta de identificación"

#: benefits/eligibility/views.py:32 benefits/eligibility/views.py:62
#: benefits/enrollment/views.py:148
#: benefits/eligibility/views.py:64 benefits/enrollment/views.py:148
msgctxt "image alt text"
msgid "core.icons.bankcardcheck"
msgstr ""
"Icono de tarjeta bancaria con símbolo sin contacto y marca de verificación"

#: benefits/eligibility/views.py:33
msgid "eligibility.pages.index.items[1].title"
msgstr "Tu tarjeta bancaria"

#: benefits/eligibility/views.py:34
msgid "eligibility.pages.index.items[1].text"
msgstr "Una tarjeta de débito o crédito"

#: benefits/eligibility/views.py:37
msgid "eligibility.pages.index.p[0]"
msgstr ""
"Este programa actualmente está disponible para personas de 65 años o más. "
"¿No tienes más de 65 años? Póngase en contacto con su proveedor de "
"transporte público para obtener información sobre los programas de descuento "
"disponibles."

#: benefits/eligibility/views.py:39
msgid "eligibility.pages.index.button"
msgstr "Listo para continuar"

#: benefits/eligibility/views.py:53
#: benefits/eligibility/views.py:55
msgid "eligibility.pages.start.title"
msgstr "Preparación"

Expand All @@ -326,11 +296,11 @@ msgstr "Tu identificación de California"
msgid "eligibility.pages.start.items[0].text"
msgstr "Licencia de conducir o tarjeta de identificación"

#: benefits/eligibility/views.py:63
#: benefits/eligibility/views.py:65
msgid "eligibility.pages.start.items[1].title"
msgstr "Tu tarjeta bancaria"

#: benefits/eligibility/views.py:64
#: benefits/eligibility/views.py:66
msgid "eligibility.pages.start.items[1].text"
msgstr "Una tarjeta de débito o crédito"

Expand All @@ -342,45 +312,45 @@ msgstr ""
"transporte público para obtener información sobre los programas de descuento "
"disponibles."

#: benefits/eligibility/views.py:69
#: benefits/eligibility/views.py:71
msgid "eligibility.pages.start.button"
msgstr "Listo para continuar"

#: benefits/eligibility/views.py:82
#: benefits/eligibility/views.py:84
msgid "eligibility.pages.confirm.title"
msgstr "Verificar su edad"

#: benefits/eligibility/views.py:83
#: benefits/eligibility/views.py:85
msgid "eligibility.pages.confirm.content_title"
msgstr "Veamos si podemos verificar su edad con el DMV"

#: benefits/eligibility/views.py:84
#: benefits/eligibility/views.py:86
msgid "eligibility.pages.confirm.p[0]"
msgstr ""
"Si tiene 65 años o más, podemos confirmar que es elegible para un descuento "
"para personas mayores cuando viaja en transporte público. Nosotros no "
"guardamos su información."

#: benefits/eligibility/views.py:157
#: benefits/eligibility/views.py:159
msgid "eligibility.pages.unverified.title"
msgstr "Edad no confirmada"

#: benefits/eligibility/views.py:158
#: benefits/eligibility/views.py:160
msgid "eligibility.pages.unverified.content_title"
msgstr "No podemos confirmar su edad"

#: benefits/eligibility/views.py:159
#: benefits/eligibility/views.py:161
msgctxt "image alt text"
msgid "core.icons.idcardquestion"
msgstr "Icono de tarjeta de identificación con signo de interrogación"

#: benefits/eligibility/views.py:160
#: benefits/eligibility/views.py:162
msgid "eligibility.pages.unverified.p[0]"
msgstr ""
"Usted todavía puede ser elegible para un descuento, pero no podemos "
"verificar su edad con el DMV."

#: benefits/eligibility/views.py:160
#: benefits/eligibility/views.py:162
msgid "eligibility.pages.unverified.p[1]"
msgstr "Comuníquese con su proveedor de transporte público para obtener ayuda."

Expand Down

0 comments on commit 7a31ad9

Please sign in to comment.