From d4bf066b96ee0e9b43976f3ee55b05c2ef5c890a Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Tue, 15 Aug 2023 17:40:58 +0000 Subject: [PATCH] refactor(eligibility/forms): config for MST CC moves Courtesy Card config into a form class specific to this agency card --- benefits/core/migrations/0002_data.py | 15 +---- benefits/eligibility/forms.py | 76 ++++++++++++++++++------ benefits/locale/en/LC_MESSAGES/django.po | 48 +++++++-------- benefits/locale/es/LC_MESSAGES/django.po | 52 ++++++++-------- 4 files changed, 110 insertions(+), 81 deletions(-) diff --git a/benefits/core/migrations/0002_data.py b/benefits/core/migrations/0002_data.py index 11d95b53fb..ba0e29286a 100644 --- a/benefits/core/migrations/0002_data.py +++ b/benefits/core/migrations/0002_data.py @@ -4,7 +4,6 @@ import os from django.db import migrations -from django.utils.translation import gettext_lazy as _ def load_data(app, *args, **kwargs): @@ -195,19 +194,7 @@ def load_data(app, *args, **kwargs): auth_provider=None, selection_label_template="eligibility/includes/selection-label--mst-courtesy-card.html", start_template="eligibility/start--mst-courtesy-card.html", - form_title=_("Agency card information"), - form_headline=_("Let’s see if we can confirm your eligibility."), - form_blurb=_("Please input your Courtesy Card number and last name below to confirm your eligibility."), - form_sub_label=_("MST Courtesy Card number"), - form_sub_help_text=_("This is a 5-digit number on the front and back of your card."), - form_sub_placeholder="12345", - form_sub_pattern=r"\d{5}", - form_input_mode="numeric", - form_max_length=5, - form_name_label=_("Last name (as it appears on Courtesy Card)"), - form_name_help_text=_("We use this to help confirm your Courtesy Card."), - form_name_placeholder="Garcia", - form_name_max_length=255, + form_class="benefits.eligibility.forms.MSTCourtesyCard", ) sacrt_senior_verifier = EligibilityVerifier.objects.create( diff --git a/benefits/eligibility/forms.py b/benefits/eligibility/forms.py index 8fc9a76889..ee029d7380 100644 --- a/benefits/eligibility/forms.py +++ b/benefits/eligibility/forms.py @@ -53,32 +53,74 @@ class EligibilityVerificationForm(forms.Form): "missing": _("This field is required."), } - def __init__(self, verifier: models.EligibilityVerifier, *args, **kwargs): - super().__init__(*args, **kwargs) + def __init__( + self, + title, + headline, + blurb, + name_label, + name_placeholder, + name_help_text, + sub_label, + sub_placeholder, + sub_help_text, + name_max_length=None, + sub_input_mode=None, + sub_max_length=None, + sub_pattern=None, + *args, + **kwargs, + ): + super().__init__(auto_id=True, label_suffix="", *args, **kwargs) + + self.title = title + self.headline = headline + self.blurb = blurb self.classes = "col-lg-6" - sub_widget = widgets.FormControlTextInput(placeholder=verifier.form_sub_placeholder) - if verifier.form_sub_pattern: - sub_widget.attrs.update({"pattern": verifier.form_sub_pattern}) - if verifier.form_input_mode: - sub_widget.attrs.update({"inputmode": verifier.form_input_mode}) - if verifier.form_max_length: - sub_widget.attrs.update({"maxlength": verifier.form_max_length}) + sub_widget = widgets.FormControlTextInput(placeholder=sub_placeholder) + if sub_pattern: + sub_widget.attrs.update({"pattern": sub_pattern}) + if sub_input_mode: + sub_widget.attrs.update({"inputmode": sub_input_mode}) + if sub_max_length: + sub_widget.attrs.update({"maxlength": sub_max_length}) self.fields["sub"] = forms.CharField( - label=_(verifier.form_sub_label), + label=sub_label, widget=sub_widget, - help_text=_(verifier.form_sub_help_text), + help_text=sub_help_text, ) - name_widget = widgets.FormControlTextInput(placeholder=verifier.form_name_placeholder) - if verifier.form_name_max_length: - name_widget.attrs.update({"maxlength": verifier.form_name_max_length}) + name_widget = widgets.FormControlTextInput(placeholder=name_placeholder) + if name_max_length: + name_widget.attrs.update({"maxlength": name_max_length}) - self.fields["name"] = forms.CharField( - label=_(verifier.form_name_label), widget=name_widget, help_text=_(verifier.form_name_help_text) - ) + self.fields["name"] = forms.CharField(label=name_label, widget=name_widget, help_text=name_help_text) def clean(self): if not recaptcha.verify(self.data): raise forms.ValidationError("reCAPTCHA failed") + + +class MSTCourtesyCard(EligibilityVerificationForm): + """EligibilityVerification form for the MST Courtesy Card.""" + + def __init__(self, *args, **kwargs): + super().__init__( + title=_("Agency card information"), + headline=_("Let’s see if we can confirm your eligibility."), + blurb=_("Please input your Courtesy Card number and last name below to confirm your eligibility."), + name_label=_("Last name (as it appears on Courtesy Card)"), + name_placeholder="Garcia", + name_help_text=_("We use this to help confirm your Courtesy Card."), + sub_label=_("MST Courtesy Card number"), + sub_help_text=_("This is a 5-digit number on the front and back of your card."), + sub_placeholder="12345", + name_max_length=255, + sub_input_mode="numeric", + sub_max_length=5, + sub_pattern=r"\d{5}", + *args, + **kwargs, + ) diff --git a/benefits/locale/en/LC_MESSAGES/django.po b/benefits/locale/en/LC_MESSAGES/django.po index 9d350affb4..5b4774c0e0 100644 --- a/benefits/locale/en/LC_MESSAGES/django.po +++ b/benefits/locale/en/LC_MESSAGES/django.po @@ -6,36 +6,13 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: https://github.com/cal-itp/benefits/issues \n" -"POT-Creation-Date: 2023-08-15 06:04+0000\n" +"POT-Creation-Date: 2023-08-15 19:08+0000\n" "Language: English\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -msgid "Agency card information" -msgstr "" - -msgid "Let’s see if we can confirm your eligibility." -msgstr "" - -msgid "" -"Please input your Courtesy Card number and last name below to confirm your " -"eligibility." -msgstr "" - -msgid "MST Courtesy Card number" -msgstr "" - -msgid "This is a 5-digit number on the front and back of your card." -msgstr "" - -msgid "Last name (as it appears on Courtesy Card)" -msgstr "" - -msgid "We use this to help confirm your Courtesy Card." -msgstr "" - msgid "Get started" msgstr "" @@ -295,6 +272,29 @@ msgstr "" msgid "This field is required." msgstr "" +msgid "Agency card information" +msgstr "" + +msgid "Let’s see if we can confirm your eligibility." +msgstr "" + +msgid "" +"Please input your Courtesy Card number and last name below to confirm your " +"eligibility." +msgstr "" + +msgid "Last name (as it appears on Courtesy Card)" +msgstr "" + +msgid "We use this to help confirm your Courtesy Card." +msgstr "" + +msgid "MST Courtesy Card number" +msgstr "" + +msgid "This is a 5-digit number on the front and back of your card." +msgstr "" + msgctxt "image alt text" msgid "Bank card icon with contactless symbol and checkmark" msgstr "" diff --git a/benefits/locale/es/LC_MESSAGES/django.po b/benefits/locale/es/LC_MESSAGES/django.po index f88caad086..2ff7b4145a 100644 --- a/benefits/locale/es/LC_MESSAGES/django.po +++ b/benefits/locale/es/LC_MESSAGES/django.po @@ -6,38 +6,13 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: https://github.com/cal-itp/benefits/issues \n" -"POT-Creation-Date: 2023-08-15 06:04+0000\n" +"POT-Creation-Date: 2023-08-15 19:08+0000\n" "Language: Español\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -msgid "Agency card information" -msgstr "Información de la tarjeta de agencia" - -msgid "Let’s see if we can confirm your eligibility." -msgstr "Veamos si podemos confirmar su elegibilidad." - -msgid "" -"Please input your Courtesy Card number and last name below to confirm your " -"eligibility." -msgstr "" -"Ingrese el número de su tarjeta de cortesía y apellido a continuación para " -"confirmar su elegibilidad." - -msgid "MST Courtesy Card number" -msgstr "Número de tarjeta de cortesía de MST" - -msgid "This is a 5-digit number on the front and back of your card." -msgstr "Este es un número de 5 dígitos en el anverso y reverso de su tarjeta." - -msgid "Last name (as it appears on Courtesy Card)" -msgstr "Apellido (tal como aparece en la tarjeta de cortesía)" - -msgid "We use this to help confirm your Courtesy Card." -msgstr "Usamos esto para ayudar a confirmar su tarjeta de cortesía." - msgid "Get started" msgstr "Comenzar" @@ -378,6 +353,31 @@ msgstr "Verifique su entrada. El formato parece incorrecto." msgid "This field is required." msgstr "Este campo es requerido." +msgid "Agency card information" +msgstr "Información de la tarjeta de agencia" + +msgid "Let’s see if we can confirm your eligibility." +msgstr "Veamos si podemos confirmar su elegibilidad." + +msgid "" +"Please input your Courtesy Card number and last name below to confirm your " +"eligibility." +msgstr "" +"Ingrese el número de su tarjeta de cortesía y apellido a continuación para " +"confirmar su elegibilidad." + +msgid "Last name (as it appears on Courtesy Card)" +msgstr "Apellido (tal como aparece en la tarjeta de cortesía)" + +msgid "We use this to help confirm your Courtesy Card." +msgstr "Usamos esto para ayudar a confirmar su tarjeta de cortesía." + +msgid "MST Courtesy Card number" +msgstr "Número de tarjeta de cortesía de MST" + +msgid "This is a 5-digit number on the front and back of your card." +msgstr "Este es un número de 5 dígitos en el anverso y reverso de su tarjeta." + msgctxt "image alt text" msgid "Bank card icon with contactless symbol and checkmark" msgstr ""