Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Eligibility index #1517

Merged
merged 6 commits into from
Jul 13, 2023
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
10 changes: 4 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"djlint.guessProfile": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[html]": {
"editor.defaultFormatter": "monosans.djlint"
},
"[django-html]": {
"editor.defaultFormatter": "monosans.djlint"
"[django-html][html]": {
"editor.defaultFormatter": "monosans.djlint",
"djlint.enableLinting": true,
"djlint.profile": "django"
},
"files.encoding": "utf8",
"files.eol": "\n",
Expand Down
4 changes: 2 additions & 2 deletions benefits/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.3 on 2023-07-08 02:54
# Generated by Django 4.2.3 on 2023-07-11 17:22

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -109,7 +109,7 @@ class Migration(migrations.Migration):
("phone", models.TextField()),
("active", models.BooleanField(default=False)),
("jws_signing_alg", models.TextField()),
("eligibility_index_intro", models.TextField()),
("eligibility_index_template", models.TextField()),
("transit_type", models.TextField()),
("eligibility_types", models.ManyToManyField(to="core.eligibilitytype")),
("eligibility_verifiers", models.ManyToManyField(to="core.eligibilityverifier")),
Expand Down
4 changes: 2 additions & 2 deletions benefits/core/migrations/0002_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def load_data(app, *args, **kwargs):
public_key=client_public_key,
jws_signing_alg=os.environ.get("MST_AGENCY_JWS_SIGNING_ALG", "RS256"),
payment_processor=mst_payment_processor,
eligibility_index_intro=_("eligibility.pages.index.p[0].mst"),
eligibility_index_template="eligibility/index--mst.html",
transit_type=_("agency.variables.mst.transit_type"),
)
mst_agency.eligibility_types.set([mst_senior_type, mst_veteran_type, mst_courtesy_card_type])
Expand All @@ -282,7 +282,7 @@ def load_data(app, *args, **kwargs):
public_key=client_public_key,
jws_signing_alg=os.environ.get("SACRT_AGENCY_JWS_SIGNING_ALG", "RS256"),
payment_processor=sacrt_payment_processor,
eligibility_index_intro=_("eligibility.pages.index.p[0].sacrt"),
eligibility_index_template="eligibility/index--sacrt.html",
transit_type=_("agency.variables.sacrt.transit_type"),
)
sacrt_agency.eligibility_types.set([sacrt_senior_type])
Expand Down
2 changes: 1 addition & 1 deletion benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class TransitAgency(models.Model):
public_key = models.ForeignKey(PemData, related_name="+", on_delete=models.PROTECT)
# The JWS-compatible signing algorithm
jws_signing_alg = models.TextField()
eligibility_index_intro = models.TextField()
eligibility_index_template = models.TextField()
transit_type = models.TextField()

def __str__(self):
Expand Down
7 changes: 7 additions & 0 deletions benefits/eligibility/templates/eligibility/index--mst.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "eligibility/index.html" %}

{% load i18n %}

{% block explanatory-text %}
<p class="pt-4 pb-4 pb-lg-8">{% translate "eligibility.pages.index.intro.mst" %}</p>
{% endblock explanatory-text %}
7 changes: 7 additions & 0 deletions benefits/eligibility/templates/eligibility/index--sacrt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "eligibility/index.html" %}

{% load i18n %}

{% block explanatory-text %}
<p class="pt-4 pb-4 pb-lg-8">{% translate "eligibility.pages.index.intro.sacrt" %}</p>
{% endblock explanatory-text %}
23 changes: 14 additions & 9 deletions benefits/eligibility/templates/eligibility/index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
{% extends "core/base.html" %}
{% load i18n %}

{% block classes %}
{{ block.super | add:" eligibility-index" }}
{% endblock classes %}

{% block page_title %}
{% translate "eligibility.pages.index.title" %}&nbsp;|&nbsp;
{% endblock page_title %}

{% block nav-buttons %}
{% include "core/includes/previous-page-link.html" %}
{% url "core:index" as url %}
{% include "core/includes/button--previous-page.html" with url=url %}
{% endblock nav-buttons %}

{% block headline %}
<div class="col-lg-10">
<h1>{% translate "eligibility.pages.index.headline" %}</h1>
</div>
{% endblock headline %}

{% block explanatory-text %}
{% for p in page.paragraphs %}<p class="pt-4 pb-4 pb-lg-8">{{ p }}</p>{% endfor %}
{% endblock explanatory-text %}

{% block inner-content %}
<div class="container">
<div class="row">
{% block forms %}
{% for f in page.forms %}
{% include "core/includes/form.html" with form=f %}
{% endfor %}
{% endblock forms %}
</div>
<div class="row">{% include "core/includes/form.html" with form=form %}</div>
</div>
{% endblock inner-content %}
2 changes: 1 addition & 1 deletion benefits/eligibility/templates/eligibility/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{% block nav-buttons %}
{% url "eligibility:index" as url %}
{% include "core/includes/button__previous_page.html" with url=url %}
{% include "core/includes/button--previous-page.html" with url=url %}
{% endblock nav-buttons %}

{% block inner-content %}
Expand Down
33 changes: 5 additions & 28 deletions benefits/eligibility/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.decorators import decorator_from_middleware
from django.utils.html import format_html
from django.utils.translation import pgettext, gettext as _

from benefits.core import recaptcha, session, viewmodels
from benefits.core.middleware import AgencySessionRequired, LoginRequired, RecaptchaEnabled, VerifierSessionRequired
from benefits.core.models import EligibilityVerifier
from benefits.core.views import ROUTE_HELP
from . import analytics, forms, verify


Expand All @@ -24,7 +22,6 @@
ROUTE_UNVERIFIED = "eligibility:unverified"
ROUTE_ENROLLMENT = "enrollment:index"

TEMPLATE_INDEX = "eligibility/index.html"
TEMPLATE_START = "eligibility/start.html"
TEMPLATE_CONFIRM = "eligibility/confirm.html"
TEMPLATE_UNVERIFIED = "eligibility/unverified.html"
Expand All @@ -50,28 +47,7 @@ def index(request, agency=None):
# this may or may not require OAuth, with a different set of scope/claims than what is already stored
session.logout(request)

eligibility_start = reverse(ROUTE_START)

help_page = reverse(ROUTE_HELP)

agency_intro = _(agency.eligibility_index_intro) if isinstance(agency.eligibility_index_intro, str) else ""
common_intro = _("eligibility.pages.index.p[0]%(info_link)s") % {"info_link": f"{help_page}#what-is-cal-itp"}
intro = format_html(agency_intro + common_intro)
page = viewmodels.Page(
title=_("eligibility.pages.index.title"),
headline=_("eligibility.pages.index.headline"),
paragraphs=[intro],
forms=forms.EligibilityVerifierSelectionForm(agency=agency),
)

ctx = page.context_dict()

origin = session.origin(request)
if origin == reverse(ROUTE_CORE_INDEX):
ctx["previous_page_button"] = viewmodels.Button.previous_page(url=origin)

ctx["help_page"] = help_page
ctx["help_text"] = format_html(_("eligibility.pages.index.help_text%(help_link)s") % {"help_link": help_page})
context = {"form": forms.EligibilityVerifierSelectionForm(agency=agency)}

if request.method == "POST":
form = forms.EligibilityVerifierSelectionForm(data=request.POST, agency=agency)
Expand All @@ -84,15 +60,16 @@ def index(request, agency=None):
types_to_verify = agency.type_names_to_verify(verifier)
analytics.selected_verifier(request, types_to_verify)

eligibility_start = reverse(ROUTE_START)
response = redirect(eligibility_start)
else:
# form was not valid, allow for correction/resubmission
if recaptcha.has_error(form):
messages.error(request, "Recaptcha failed. Please try again.")
page.forms = [form]
response = TemplateResponse(request, TEMPLATE_INDEX, ctx)
context["form"] = form
response = TemplateResponse(request, agency.eligibility_index_template, context)
else:
response = TemplateResponse(request, TEMPLATE_INDEX, ctx)
response = TemplateResponse(request, agency.eligibility_index_template, context)

return response

Expand Down
105 changes: 44 additions & 61 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: 2023-07-12 05:34+0000\n"
"POT-Creation-Date: 2023-07-13 16:41+0000\n"
"Language: English\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -55,20 +55,9 @@ msgstr ""
"That’s okay! You may still be eligible for our program. Please reach out to "
"Monterey-Salinas Transit for assistance."

msgid "eligibility.pages.index.p[0].mst"
msgstr ""
"You can tap your credit or debit card when you board an MST bus, and your "
"discounted fare will automatically apply every time you ride. "

msgid "agency.variables.mst.transit_type"
msgstr "bus"

msgid "eligibility.pages.index.p[0].sacrt"
msgstr ""
"You can tap your credit or debit card when you board SacRT public "
"transportation, and your discounted fare will automatically apply every time "
"you ride. "

msgid "agency.variables.sacrt.transit_type"
msgstr "light rail"

Expand Down Expand Up @@ -275,33 +264,6 @@ msgstr ""
"To function properly, this website requires a browser that supports "
"JavaScript. Please enable JavaScript for this website and"

msgid "eligibility.pages.index.mst_courtesy_card.label"
msgstr "I have an MST Courtesy Card"

msgid "eligibility.pages.index.mst_courtesy_card.description"
msgstr ""
"This option is for people who have a current Courtesy Card or an MST RIDES "
"Eligibility card. This benefit may need to be renewed in the future. Using "
"this benefit means your new transit fare is half of the standard fare."

msgid "eligibility.pages.index.senior.label"
msgstr "Older Adult"

msgid "eligibility.pages.index.senior.description"
msgstr ""
"You must be 65 years or older. You will need to verify your identity with"

msgid "eligibility.pages.index.veteran.label"
msgstr "US Veteran"

msgid "eligibility.pages.index.veteran.description"
msgstr ""
"This option is for people who have served in the active military, naval, or "
"air service, and who were discharged or released therefrom under conditions "
"other than dishonorable. You will need to <a href='https://www.va.gov/"
"resources/verifying-your-identity-on-vagov/' target=\"_blank\" rel="
"\"noopener noreferrer\">verify your identity through VA.gov</a>"

msgid "core.pages.index.button"
msgstr "Choose your Provider"

Expand All @@ -316,7 +278,7 @@ msgid "core.pages.logged_out.headline[1]"
msgstr "Thank you for using Cal-ITP Benefits!"

msgid "eligibility.pages.index.label"
msgstr "Select the option that best applies to you:"
msgstr "Which transit benefit would you like to enroll in?"

msgid "core.pages.error.title"
msgstr "Error"
Expand Down Expand Up @@ -501,6 +463,48 @@ msgstr ""
"gov/help/' target=\"_blank\" rel=\"noopener noreferrer\">Login.gov Help "
"Center</a>"

msgid "eligibility.pages.index.mst_courtesy_card.label"
msgstr "MST Courtesy Card"

msgid "eligibility.pages.index.mst_courtesy_card.description"
msgstr ""
"This option is for people who have a current Courtesy Card [optional "
"qualifier]."

msgid "eligibility.pages.index.senior.label"
msgstr "Older Adult"

msgid "eligibility.pages.index.senior.description"
msgstr ""
"You must be 65 years or older. You will need to verify your identity with"

msgid "eligibility.pages.index.veteran.label"
msgstr "US Veteran"

msgid "eligibility.pages.index.veteran.description"
msgstr ""
"This option is for people who have served in the active military, naval, or "
"air service, and who were discharged or released therefrom under conditions "
"other than dishonorable. You will need to <a href='https://www.va.gov/"
"resources/verifying-your-identity-on-vagov/' target=\"_blank\" "
"rel=\"noopener noreferrer\">verify your identity through VA.gov</a>"

msgid "eligibility.pages.index.intro.mst"
msgstr ""
"Cal-ITP doesn’t save any of your information. All MST transit benefits "
"[action] by [rate of discount] for [affected service] on [transit options]."

msgid "eligibility.pages.index.intro.sacrt"
msgstr ""
"Cal-ITP doesn’t save any of your information. All SacRT transit benefits "
"[action] by [rate of discount] for [affected service] on [transit options]."

msgid "eligibility.pages.index.title"
msgstr "Choose benefit option"

msgid "eligibility.pages.index.headline"
msgstr "Choose the transit benefit you would like to enroll in"

msgid "eligibility.pages.start.sub_headline"
msgstr "You will need a few items to connect your benefit:"

Expand Down Expand Up @@ -537,27 +541,6 @@ msgstr "You selected a Veteran transit benefit."
msgid "eligibility.buttons.veteran.signin"
msgstr "Continue to VA.gov"

#, python-format
msgid "eligibility.pages.index.p[0]%(info_link)s"
msgstr ""
"Cal-ITP doesn’t save any of your information, and you don’t need to create "
"an account. Verify to get your benefit, and connect your bank card today. "
"<strong><a class='info-link' href=\"%(info_link)s\">Learn more about Cal-ITP "
"Benefits.</a></strong>"

msgid "eligibility.pages.index.title"
msgstr "Select a benefit option"

msgid "eligibility.pages.index.headline"
msgstr ""
"Connect your bank card to your public transit discount with Cal-ITP Benefits."

#, python-format
msgid "eligibility.pages.index.help_text%(help_link)s"
msgstr ""
"Not sure which option is right for you? Please visit our <a href="
"\"%(help_link)s\">Help Page</a>."

msgid "eligibility.pages.unverified.headline"
msgstr "Your eligibility could not be verified."

Expand Down
Loading