Repository: cal-itp/benefits

Issue:
Refactor start page context creation
I got a strange error on the Start page:

```
Traceback (most recent call last):
  File "/home/calitp/.local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/calitp/.local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/calitp/.local/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/calitp/.local/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/calitp/app/benefits/eligibility/views.py", line 127, in start
    ctx["media"].insert(0, auth_media)

Exception Type: UnboundLocalError at /eligibility/start
Exception Value: local variable 'auth_media' referenced before assignment
```

Maybe now that the media list refactor and the login button are merged into dev, we can clean up the logic and context creation for this view?

## Steps to recreate

1. From start page, click "Continue with Login.gov" button
2. Sign in with Login.gov account
3. Land on confirm page (DMV form)
4. Change URL manually to `/eligibility` (the verifier select page)
5. Select "Senior Discount Program", click "Continue"
6. 💥 


Discussion:

Resolving patch:
diff --git a/benefits/eligibility/views.py b/benefits/eligibility/views.py
--- a/benefits/eligibility/views.py
+++ b/benefits/eligibility/views.py
@@ -62,43 +62,8 @@ def start(request):
     session.update(request, eligibility_types=[], origin=reverse("eligibility:start"))
     verifier = session.verifier(request)
 
-    if verifier.requires_authentication and not session.auth(request):
-        if OAUTH_CLIENT_NAME is None:
-            raise Exception("EligibilityVerifier requires authentication, but OAUTH_CLIENT_NAME is None")
-
-        auth_provider = verifier.auth_provider
-        button = viewmodels.Button.external(
-            text=_(auth_provider.sign_in_button_label),
-            url=reverse("oauth:login"),
-            id="login",
-        )
-        auth_media = dict(
-            icon=viewmodels.Icon("idscreencheck", pgettext("image alt text", "core.icons.idscreencheck")),
-            heading=_("eligibility.media.heading"),
-            details=_("eligibility.media.details"),
-            links=[
-                viewmodels.Button.link(
-                    classes="btn-text btn-link",
-                    text=_("eligibility.media.link_text"),
-                    url=_("eligibility.media.link_url"),
-                    target="_blank",
-                    rel="noopener noreferrer",
-                )
-            ],
-        )
-    else:
-        button = viewmodels.Button.primary(text=_("eligibility.buttons.continue"), url=reverse("eligibility:confirm"))
-
-    page = viewmodels.Page(
-        title=_("eligibility.pages.start.title"),
-        noimage=True,
-        paragraphs=[_(verifier.start_blurb)],
-        button=button,
-    )
-
-    ctx = page.context_dict()
-    ctx["title"] = _(verifier.start_content_title)
-    ctx["media"] = [
+    button = viewmodels.Button.primary(text=_("eligibility.buttons.continue"), url=reverse("eligibility:confirm"))
+    media = [
         dict(
             icon=viewmodels.Icon("idcardcheck", pgettext("image alt text", "core.icons.idcardcheck")),
             heading=_(verifier.start_item_name),
@@ -124,7 +89,44 @@ def start(request):
     ]
 
     if verifier.requires_authentication:
-        ctx["media"].insert(0, auth_media)
+        if OAUTH_CLIENT_NAME is None:
+            raise Exception("EligibilityVerifier requires authentication, but OAUTH_CLIENT_NAME is None")
+
+        media.insert(
+            0,
+            dict(
+                icon=viewmodels.Icon("idscreencheck", pgettext("image alt text", "core.icons.idscreencheck")),
+                heading=_("eligibility.media.heading"),
+                details=_("eligibility.media.details"),
+                links=[
+                    viewmodels.Button.link(
+                        classes="btn-text btn-link",
+                        text=_("eligibility.media.link_text"),
+                        url=_("eligibility.media.link_url"),
+                        target="_blank",
+                        rel="noopener noreferrer",
+                    )
+                ],
+            ),
+        )
+
+        if not session.auth(request):
+            button = viewmodels.Button.external(
+                text=_(verifier.auth_provider.sign_in_button_label),
+                url=reverse("oauth:login"),
+                id="login",
+            )
+
+    page = viewmodels.Page(
+        title=_("eligibility.pages.start.title"),
+        noimage=True,
+        paragraphs=[_(verifier.start_blurb)],
+        button=button,
+    )
+
+    ctx = page.context_dict()
+    ctx["title"] = _(verifier.start_content_title)
+    ctx["media"] = media
 
     return TemplateResponse(request, "eligibility/start.html", ctx)
 


Test patch: