Skip to content

Refactor: class-based view for Eligibility Index - #3065

Merged
angela-tran merged 6 commits into
mainfrom
refactor/cbv-eligibility-index
Aug 8, 2025
Merged

Refactor: class-based view for Eligibility Index#3065
angela-tran merged 6 commits into
mainfrom
refactor/cbv-eligibility-index

Conversation

@angela-tran

Copy link
Copy Markdown
Member

Closes #2868

This PR converts the eligibility index view function into a class-based view.

The corresponding copy context for the Eligibility Index was moved into the CBV's get_context_data method.

Open question

This PR is all working and technically ready to merge, but I wanted to call something out for discussion and to get ahead of this PR possibly having a "surprising" effect 😣 ...

In our other CBV refactors, I haven't seen us move the copy context objects into the CBV, but I thought this was one of the main reasons for moving to CBVs (#2777). I'm trying my best to help us achieve what we set out to do but am feeling like this PR might cause controversy because it's deviating from the norm.

@angela-tran angela-tran self-assigned this Aug 6, 2025
@angela-tran
angela-tran requested a review from a team as a code owner August 6, 2025 22:26
@github-actions github-actions Bot added back-end Django views, sessions, middleware, models, migrations etc. i18n Copy: Language files or Django i18n framework tests Related to automated testing (unit, UI, integration, etc.) labels Aug 6, 2025
@angela-tran
angela-tran force-pushed the refactor/cbv-eligibility-index branch from f62683f to 4e7347d Compare August 6, 2025 22:26
@github-actions

github-actions Bot commented Aug 6, 2025

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/core
  widgets.py
  benefits/core/models
  transit.py
  benefits/eligibility
  urls.py
  views.py 114-116
  benefits/eligibility/context
  __init__.py
Project Total  

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

@lalver1 lalver1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for highlighting how this PR differs from previous ones in that it moves the context into the CBV as we set out initially, and thanks for this reminder 🙂

I tend to prefer this approach since the context and the view are now in the same place. If we need to update or add copy later, it seems that this setup makes it easier to find it since the context is closer to the view (and consequently the html via template_name). The code inside the views does get longer, but maybe that's ok?

Just noticed a minor typo, unrelated to the open question, in the comment below

Comment thread benefits/eligibility/views.py Outdated
flow_id = form.cleaned_data.get("flow")
flow = EnrollmentFlow.objects.get(id=flow_id)
session.update(request, flow=flow)
eligibliity_index = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor typo (eligibliity) here and in the context.update() line below

@angela-tran
angela-tran force-pushed the refactor/cbv-eligibility-index branch from 4e7347d to 8264b2f Compare August 7, 2025 19:26
@thekaveman

thekaveman commented Aug 7, 2025

Copy link
Copy Markdown
Member

RE: your open question @angela-tran

I'm glad you decided to just do this here. I was kind of avoiding it because it seemed like another layer of things to think about (OK OK, I was lazy 😅).

But I agree with you and Luis, it makes a lot of sense to keep things self-contained in the CBVs.

Originally originally, we even had the idea to have a module (file) for each CBV. As we move context data into the views, we may want to go back to that idea to make for more reasonable and readable file sizes.

@angela-tran
angela-tran force-pushed the refactor/cbv-eligibility-index branch 2 times, most recently from 786a38a to c864006 Compare August 7, 2025 22:34
@thekaveman

Copy link
Copy Markdown
Member

@angela-tran you may want to rebase on the latest main to get the pip install fixes.

@angela-tran
angela-tran force-pushed the refactor/cbv-eligibility-index branch from c864006 to 0b21a62 Compare August 7, 2025 23:02
@angela-tran
angela-tran requested a review from lalver1 August 7, 2025 23:03
@angela-tran

Copy link
Copy Markdown
Member Author

Thanks @lalver1 and @thekaveman for adding your thoughts. It makes sense that there was hesitation around moving the context over since clearly I had hesitation too about what questions it would potentially open up. Glad to hear this is still the direction we want to go.

@lalver1 lalver1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great @angela-tran! 🎉

@angela-tran
angela-tran merged commit 4ade9d6 into main Aug 8, 2025
14 checks passed
@angela-tran
angela-tran deleted the refactor/cbv-eligibility-index branch August 8, 2025 16:25
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. i18n Copy: Language files or Django i18n framework tests Related to automated testing (unit, UI, integration, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Class-based views: Eligibility index

3 participants