Skip to content

Commit

Permalink
refactor(eligibility/forms): config for MST CC
Browse files Browse the repository at this point in the history
moves Courtesy Card config into a form class specific to this agency
card
  • Loading branch information
thekaveman committed Aug 15, 2023
1 parent b721370 commit d4bf066
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 81 deletions.
15 changes: 1 addition & 14 deletions benefits/core/migrations/0002_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
76 changes: 59 additions & 17 deletions benefits/eligibility/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
48 changes: 24 additions & 24 deletions benefits/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""
Expand Down
52 changes: 26 additions & 26 deletions benefits/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 ""
Expand Down

0 comments on commit d4bf066

Please sign in to comment.