Skip to content

Commit 0b21a62

Browse files
committed
refactor(context): move Eligibility Index context into CBV
one of the main motivations for the CBV refactor is to consolidate and localize the data needed for views.
1 parent 714b141 commit 0b21a62

7 files changed

Lines changed: 147 additions & 162 deletions

File tree

benefits/core/models/transit.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from django.urls import reverse
88

99
from benefits.core import context as core_context
10-
from benefits.eligibility import context as eligibility_context
1110
from benefits.routes import routes
1211
from .common import Environment, PemData
1312

@@ -168,10 +167,6 @@ def index_url(self):
168167
"""Public-facing URL to the TransitAgency's landing page."""
169168
return reverse(routes.AGENCY_INDEX, args=[self.slug])
170169

171-
@property
172-
def eligibility_index_context(self):
173-
return eligibility_context.eligibility_index[self.slug].dict()
174-
175170
@property
176171
def eligibility_index_url(self):
177172
"""Public facing URL to the TransitAgency's eligibility page."""
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from .agency import eligibility_index
21
from .flow import eligibility_start, eligibility_unverified
32

4-
__all__ = ["eligibility_index", "eligibility_start", "eligibility_unverified"]
3+
__all__ = ["eligibility_start", "eligibility_unverified"]

benefits/eligibility/context/agency.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

benefits/eligibility/views.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
from benefits.routes import routes
1313
from benefits.core import recaptcha, session
14+
from benefits.core.context.agency import AgencySlug
15+
from benefits.core.context import formatted_gettext_lazy as _
1416
from benefits.core.middleware import AgencySessionRequired, RecaptchaEnabled, FlowSessionRequired
1517
from benefits.core.mixins import AgencySessionRequiredMixin, FlowSessionRequiredMixin, RecaptchaEnabledMixin
1618
from benefits.core.models import EnrollmentFlow
@@ -19,6 +21,17 @@
1921
TEMPLATE_CONFIRM = "eligibility/confirm.html"
2022

2123

24+
class EligibilityIndex:
25+
def __init__(self, form_text):
26+
if not isinstance(form_text, list):
27+
form_text = [form_text]
28+
29+
self.form_text = form_text
30+
31+
def dict(self):
32+
return dict(form_text=self.form_text)
33+
34+
2235
class IndexView(AgencySessionRequiredMixin, RecaptchaEnabledMixin, FormView):
2336
"""View handler for the enrollment flow selection form."""
2437

@@ -34,7 +47,49 @@ def get_form_kwargs(self):
3447
def get_context_data(self, **kwargs):
3548
"""Add agency-specific context data."""
3649
context = super().get_context_data(**kwargs)
37-
context.update(self.agency.eligibility_index_context)
50+
51+
eligiblity_index = {
52+
AgencySlug.CST.value: EligibilityIndex(
53+
form_text=_(
54+
"Cal-ITP doesn’t save any of your information. "
55+
"All CST transit benefits reduce fares by 50%% for bus service on fixed routes.".replace("%%", "%")
56+
)
57+
),
58+
AgencySlug.MST.value: EligibilityIndex(
59+
form_text=_(
60+
"Cal-ITP doesn’t save any of your information. "
61+
"All MST transit benefits reduce fares by 50%% for bus service on fixed routes.".replace("%%", "%")
62+
)
63+
),
64+
AgencySlug.NEVCO.value: EligibilityIndex(
65+
form_text=_(
66+
"Cal-ITP doesn’t save any of your information. "
67+
"All Nevada County Connects transit benefits reduce fares "
68+
"by 50%% for bus service on fixed routes.".replace("%%", "%")
69+
)
70+
),
71+
AgencySlug.SACRT.value: EligibilityIndex(
72+
form_text=_(
73+
"Cal-ITP doesn’t save any of your information. "
74+
"All SacRT transit benefits reduce fares by 50%% for bus service on fixed routes.".replace("%%", "%")
75+
)
76+
),
77+
AgencySlug.SBMTD.value: EligibilityIndex(
78+
form_text=_(
79+
"Cal-ITP doesn’t save any of your information. "
80+
"All SBMTD transit benefits reduce fares by 50%% for bus service on fixed routes.".replace("%%", "%")
81+
)
82+
),
83+
AgencySlug.VCTC.value: EligibilityIndex(
84+
form_text=_(
85+
"Cal-ITP doesn’t save any of your information. "
86+
"All Ventura County Transportation Commission transit benefits "
87+
"reduce fares by 50%% for bus service on fixed routes.".replace("%%", "%")
88+
)
89+
),
90+
}
91+
92+
context.update(eligiblity_index[self.agency.slug].dict())
3893
return context
3994

4095
def get(self, request, *args, **kwargs):

benefits/locale/en/LC_MESSAGES/django.po

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
msgid ""
77
msgstr ""
88
"Report-Msgid-Bugs-To: https://github.com/cal-itp/benefits/issues \n"
9-
"POT-Creation-Date: 2025-07-30 18:48-0700\n"
9+
"POT-Creation-Date: 2025-08-06 15:07-0700\n"
1010
"Language: English\n"
1111
"MIME-Version: 1.0\n"
1212
"Content-Type: text/plain; charset=UTF-8\n"
@@ -411,43 +411,6 @@ msgstr ""
411411
msgid "Which transit benefit would you like to enroll in?"
412412
msgstr ""
413413

414-
#, python-format
415-
msgid ""
416-
"Cal-ITP doesn’t save any of your information. All CST transit benefits "
417-
"reduce fares by 50%% for bus service on fixed routes."
418-
msgstr ""
419-
420-
#, python-format
421-
msgid ""
422-
"Cal-ITP doesn’t save any of your information. All MST transit benefits "
423-
"reduce fares by 50%% for bus service on fixed routes."
424-
msgstr ""
425-
426-
#, python-format
427-
msgid ""
428-
"Cal-ITP doesn’t save any of your information. All Nevada County Connects "
429-
"transit benefits reduce fares by 50%% for bus service on fixed routes."
430-
msgstr ""
431-
432-
#, python-format
433-
msgid ""
434-
"Cal-ITP doesn’t save any of your information. All SacRT transit benefits "
435-
"reduce fares by 50%% for bus service on fixed routes."
436-
msgstr ""
437-
438-
#, python-format
439-
msgid ""
440-
"Cal-ITP doesn’t save any of your information. All SBMTD transit benefits "
441-
"reduce fares by 50%% for bus service on fixed routes."
442-
msgstr ""
443-
444-
#, python-format
445-
msgid ""
446-
"Cal-ITP doesn’t save any of your information. All Ventura County "
447-
"Transportation Commission transit benefits reduce fares by 50%% for bus "
448-
"service on fixed routes."
449-
msgstr ""
450-
451414
msgid "Get started with"
452415
msgstr ""
453416

@@ -760,6 +723,43 @@ msgstr ""
760723
msgid "Please reach out to %(short_name)s for assistance."
761724
msgstr ""
762725

726+
#, python-format
727+
msgid ""
728+
"Cal-ITP doesn’t save any of your information. All CST transit benefits "
729+
"reduce fares by 50%% for bus service on fixed routes."
730+
msgstr ""
731+
732+
#, python-format
733+
msgid ""
734+
"Cal-ITP doesn’t save any of your information. All MST transit benefits "
735+
"reduce fares by 50%% for bus service on fixed routes."
736+
msgstr ""
737+
738+
#, python-format
739+
msgid ""
740+
"Cal-ITP doesn’t save any of your information. All Nevada County Connects "
741+
"transit benefits reduce fares by 50%% for bus service on fixed routes."
742+
msgstr ""
743+
744+
#, python-format
745+
msgid ""
746+
"Cal-ITP doesn’t save any of your information. All SacRT transit benefits "
747+
"reduce fares by 50%% for bus service on fixed routes."
748+
msgstr ""
749+
750+
#, python-format
751+
msgid ""
752+
"Cal-ITP doesn’t save any of your information. All SBMTD transit benefits "
753+
"reduce fares by 50%% for bus service on fixed routes."
754+
msgstr ""
755+
756+
#, python-format
757+
msgid ""
758+
"Cal-ITP doesn’t save any of your information. All Ventura County "
759+
"Transportation Commission transit benefits reduce fares by 50%% for bus "
760+
"service on fixed routes."
761+
msgstr ""
762+
763763
msgid "Your eligibility is confirmed! You’re almost there."
764764
msgstr ""
765765

benefits/locale/es/LC_MESSAGES/django.po

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
msgid ""
77
msgstr ""
88
"Report-Msgid-Bugs-To: https://github.com/cal-itp/benefits/issues \n"
9-
"POT-Creation-Date: 2025-07-30 18:48-0700\n"
9+
"POT-Creation-Date: 2025-08-06 15:07-0700\n"
1010
"Language: Español\n"
1111
"MIME-Version: 1.0\n"
1212
"Content-Type: text/plain; charset=UTF-8\n"
@@ -564,57 +564,6 @@ msgstr "Ha cerrado sesión correctamente. ¡Gracias por usar Cal-ITP Benefits!"
564564
msgid "Which transit benefit would you like to enroll in?"
565565
msgstr "¿A qué beneficio de tránsito le gustaría inscribirse?"
566566

567-
#, python-format
568-
msgid ""
569-
"Cal-ITP doesn’t save any of your information. All CST transit benefits "
570-
"reduce fares by 50%% for bus service on fixed routes."
571-
msgstr ""
572-
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de CST "
573-
"reducen las tarifas de autobuses en un 50%%."
574-
575-
#, python-format
576-
msgid ""
577-
"Cal-ITP doesn’t save any of your information. All MST transit benefits "
578-
"reduce fares by 50%% for bus service on fixed routes."
579-
msgstr ""
580-
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de MST "
581-
"reducen las tarifas de autobuses en un 50%%."
582-
583-
#, python-format
584-
msgid ""
585-
"Cal-ITP doesn’t save any of your information. All Nevada County Connects "
586-
"transit benefits reduce fares by 50%% for bus service on fixed routes."
587-
msgstr ""
588-
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de "
589-
"Nevada County Connects reducen las tarifas de autobuses en un 50%%."
590-
591-
#, python-format
592-
msgid ""
593-
"Cal-ITP doesn’t save any of your information. All SacRT transit benefits "
594-
"reduce fares by 50%% for bus service on fixed routes."
595-
msgstr ""
596-
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de "
597-
"SacRT reducen las tarifas en un 50%% para el servicio de autobús en rutas "
598-
"fijas."
599-
600-
#, python-format
601-
msgid ""
602-
"Cal-ITP doesn’t save any of your information. All SBMTD transit benefits "
603-
"reduce fares by 50%% for bus service on fixed routes."
604-
msgstr ""
605-
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de "
606-
"SBMTD le ofrecen a los pasajeros tarifas de autobús reducidas."
607-
608-
#, python-format
609-
msgid ""
610-
"Cal-ITP doesn’t save any of your information. All Ventura County "
611-
"Transportation Commission transit benefits reduce fares by 50%% for bus "
612-
"service on fixed routes."
613-
msgstr ""
614-
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de "
615-
"Ventura County Transportation Commission reducen las tarifas de autobuses en "
616-
"un 50%%."
617-
618567
msgid "Get started with"
619568
msgstr "Comience con"
620569

@@ -975,6 +924,57 @@ msgstr "¡Está bien! Usted aún puede ser elegible para nuestro programa."
975924
msgid "Please reach out to %(short_name)s for assistance."
976925
msgstr "Comuníquese con %(short_name)s para obtener ayuda."
977926

927+
#, python-format
928+
msgid ""
929+
"Cal-ITP doesn’t save any of your information. All CST transit benefits "
930+
"reduce fares by 50%% for bus service on fixed routes."
931+
msgstr ""
932+
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de CST "
933+
"reducen las tarifas de autobuses en un 50%%."
934+
935+
#, python-format
936+
msgid ""
937+
"Cal-ITP doesn’t save any of your information. All MST transit benefits "
938+
"reduce fares by 50%% for bus service on fixed routes."
939+
msgstr ""
940+
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de MST "
941+
"reducen las tarifas de autobuses en un 50%%."
942+
943+
#, python-format
944+
msgid ""
945+
"Cal-ITP doesn’t save any of your information. All Nevada County Connects "
946+
"transit benefits reduce fares by 50%% for bus service on fixed routes."
947+
msgstr ""
948+
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de "
949+
"Nevada County Connects reducen las tarifas de autobuses en un 50%%."
950+
951+
#, python-format
952+
msgid ""
953+
"Cal-ITP doesn’t save any of your information. All SacRT transit benefits "
954+
"reduce fares by 50%% for bus service on fixed routes."
955+
msgstr ""
956+
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de "
957+
"SacRT reducen las tarifas en un 50%% para el servicio de autobús en rutas "
958+
"fijas."
959+
960+
#, python-format
961+
msgid ""
962+
"Cal-ITP doesn’t save any of your information. All SBMTD transit benefits "
963+
"reduce fares by 50%% for bus service on fixed routes."
964+
msgstr ""
965+
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de "
966+
"SBMTD le ofrecen a los pasajeros tarifas de autobús reducidas."
967+
968+
#, python-format
969+
msgid ""
970+
"Cal-ITP doesn’t save any of your information. All Ventura County "
971+
"Transportation Commission transit benefits reduce fares by 50%% for bus "
972+
"service on fixed routes."
973+
msgstr ""
974+
"Cal-ITP no almacena su información. Todos los beneficios de tránsito de "
975+
"Ventura County Transportation Commission reducen las tarifas de autobuses en "
976+
"un 50%%."
977+
978978
msgid "Your eligibility is confirmed! You’re almost there."
979979
msgstr "¡Su elegibilidad está confirmada! Ya falta poco."
980980

tests/pytest/eligibility/context/test_agency.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)