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: simplify Eligibility Start templates #2726

Merged
merged 8 commits into from
Mar 18, 2025

Conversation

angela-tran
Copy link
Member

@angela-tran angela-tran commented Mar 7, 2025

Closes #2728

This PR refactors the eligibility.start view so that it uses a single template. It uses a context dictionary from the flow to provide the template with copy.

The EligibilityStart class models the pieces of copy that are needed for the page. I noticed enough duplication with the Login.gov-based instances and also with the agency-card instances of EligibilityStart, so I decided to create subclasses - LoginGovEligibilityStart and AgencyCardEligibilityStart - to consolidate the copy that was being duplicated.

Testing locally

  • Run migrations - ./bin/init.sh
  • Launch the app
  • Check that the Eligibility Start page for each distinct flow looks exactly the same as before ( 😁 )

@angela-tran angela-tran self-assigned this Mar 7, 2025
@github-actions github-actions bot added back-end Django views, sessions, middleware, models, migrations etc. front-end HTML/CSS/JavaScript and Django templates labels Mar 7, 2025
@angela-tran angela-tran changed the title WIP - Refactor: Eligibility Start context WIP - Refactor: simplify Eligibility Start templates Mar 7, 2025
@thekaveman thekaveman linked an issue Mar 7, 2025 that may be closed by this pull request
Base automatically changed from refactor/eligibility-index-context to main March 13, 2025 16:29
@angela-tran angela-tran force-pushed the refactor/eligibility-start-context branch from 656e62f to 380e89a Compare March 13, 2025 17:46
@angela-tran angela-tran changed the title WIP - Refactor: simplify Eligibility Start templates Refactor: simplify Eligibility Start templates Mar 13, 2025
Copy link

github-actions bot commented Mar 13, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits
  admin.py
  benefits/core/models
  enrollment.py
  benefits/eligibility
  views.py
  benefits/eligibility/context
  __init__.py
  flow.py
Project Total  

This report was generated by python-coverage-comment-action

@angela-tran angela-tran force-pushed the refactor/eligibility-start-context branch 3 times, most recently from 5411cf0 to 6d60b5c Compare March 13, 2025 18:33
@angela-tran angela-tran force-pushed the refactor/eligibility-start-context branch from 6d60b5c to 25bc8e4 Compare March 13, 2025 18:42
Copy link

@angela-tran angela-tran force-pushed the refactor/eligibility-start-context branch from c113f0e to 4fc9821 Compare March 13, 2025 22:14
EnrollmentFlow model was updated to replace eligibility_start_template_override
with eligibility_start_context.
they kept failing with an error saying that `eligibility_start_context`
was a MagicMock instead of a dict.

when running with a debugger, I could see that `session.flow` returns
a MagicMock. maybe that was fine before, but now we need to use the
actual test model instance.
@angela-tran angela-tran force-pushed the refactor/eligibility-start-context branch from 4fc9821 to 57f2faf Compare March 13, 2025 22:28
@angela-tran angela-tran marked this pull request as ready for review March 13, 2025 22:36
@angela-tran angela-tran requested a review from a team as a code owner March 13, 2025 22:36
Copy link
Member

@lalver1 lalver1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! I liked the organization/cleanup in 0b3c428 and 6e067f9

Also tested locally and compared it on the browser with https://dev-benefits.calitp.org/ and the Eligibility Start page looked identical 👍

class EligibilityStart:
page_title: str
headline_text: str
eligibility_item_template: str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can take a follow-up item to refactor this field away from using these templates, and to encode the item strings directly in context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, great idea! Created #2759 for it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it in the sprint, but feel free to change that if you disagree

{% include "eligibility/includes/eligibility-item--contactless-card--start.html" %}
</ul>
{% endblock inner-content %}

{% block call-to-action-button %}
{% translate call_to_action_button.text as button_text %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I was wondering about when working on #2753:

Since we already use the gettext() helper (aliased as _()) setting up the context, to mark the string as translatable -- do we also need to translate the string in the template with this {% translate %} (or {% blocktranslate %} tag?

I think the answer, from #2753 anyway, seems to be: no. You can just render the variable directly in the template and it will be translated as necessary. E.g. this template change: https://github.com/cal-itp/benefits/pull/2753/files#diff-70ed6fd5fa2321e83db0d63df8312f680cd40428de4ada50dab22e93f55db7c7R109

Translation still works image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we can remove translate from the templates 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking to merge this PR as-is, and a follow-up PR can remove the unnecessary translates in the templates

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #2760 as that follow-up ticket

@angela-tran angela-tran merged commit 4e9af9c into main Mar 18, 2025
16 checks passed
@angela-tran angela-tran deleted the refactor/eligibility-start-context branch March 18, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back-end Django views, sessions, middleware, models, migrations etc. front-end HTML/CSS/JavaScript and Django templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify templates: Eligibility Start
3 participants