prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Auto select Transit Agency when only 1 Active
  Simplify the flow for a user, and avoid having to deal with the design of a single button on the `core:index` page.
  
  When there is only 1 active transit agency, and user lands on `core:index`, forward to the active agency's `core:agency_index` page.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `benefits/core/views.py`
  Content:
  ```
  1 """
  2 The core application: view definition for the root of the webapp.
  3 """
  4 from django.http import HttpResponseBadRequest, HttpResponseNotFound, HttpResponseServerError
  5 from django.template import loader
  6 from django.template.response import TemplateResponse
  7 from django.urls import reverse
  8 from django.utils.translation import gettext as _
  9 
  10 from . import models, session, viewmodels
  11 from .middleware import pageview_decorator
  12 
  13 
  14 def PageTemplateResponse(request, page_vm):
  15     """Helper returns a TemplateResponse using the common page template."""
  16     return TemplateResponse(request, "core/page.html", page_vm.context_dict())
  17 
  18 
  19 def _index_content_title():
  20     """Helper returns the content title for the common index page."""
  21     return _("core.pages.index.content_title")
  22 
  23 
  24 def _index_url():
  25     """Helper computes the index url path."""
  26     return reverse("core:index")
  27 
  28 
  29 @pageview_decorator
  30 def index(request):
  31     """View handler for the main entry page."""
  32     session.reset(request)
  33 
  34     # generate a button to the landing page for each active agency
  35     agencies = models.TransitAgency.all_active()
  36     buttons = [viewmodels.Button.outline_primary(text=a.short_name, url=a.index_url) for a in agencies]
  37     buttons[0].classes.append("mt-3")
  38     buttons[0].label = _("core.pages.index.chooseprovider")
  39 
  40     page = viewmodels.Page(
  41         title=_("core.pages.index.title"),
  42         content_title=_index_content_title(),
  43         buttons=buttons,
  44         classes="home",
  45     )
  46 
  47     return PageTemplateResponse(request, page)
  48 
  49 
  50 @pageview_decorator
  51 def agency_index(request, agency):
  52     """View handler for an agency entry page."""
  53     session.reset(request)
  54     session.update(request, agency=agency, origin=agency.index_url)
  55 
  56     button = viewmodels.Button.primary(text=_("core.pages.index.continue"), url=reverse("eligibility:index"))
  57     button.label = _("core.pages.agency_index.button.label")
  58 
  59     page = viewmodels.Page(
  60         title=_("core.pages.agency_index.title"),
  61         content_title=_("core.pages.agency_index.content_title"),
  62         button=button,
  63         classes="home",
  64     )
  65 
  66     help_page = reverse("core:help")
  67     context_dict = {**page.context_dict(), **{"info_link": f"{help_page}#about"}}
  68 
  69     return TemplateResponse(request, "core/agency_index.html", context_dict)
  70 
  71 
  72 @pageview_decorator
  73 def help(request):
  74     """View handler for the help page."""
  75     if session.active_agency(request):
  76         agency = session.agency(request)
  77         buttons = viewmodels.Button.agency_contact_links(agency)
  78     else:
  79         buttons = [btn for a in models.TransitAgency.all_active() for btn in viewmodels.Button.agency_contact_links(a)]
  80 
  81     buttons.append(viewmodels.Button.home(request, _("core.buttons.back")))
  82 
  83     page = viewmodels.Page(
  84         title=_("core.buttons.help"),
  85         content_title=_("core.buttons.help"),
  86         buttons=buttons,
  87         noimage=True,
  88     )
  89 
  90     return TemplateResponse(request, "core/help.html", page.context_dict())
  91 
  92 
  93 @pageview_decorator
  94 def bad_request(request, exception, template_name="400.html"):
  95     """View handler for HTTP 400 Bad Request responses."""
  96     if session.active_agency(request):
  97         session.update(request, origin=session.agency(request).index_url)
  98     else:
  99         session.update(request, origin=_index_url())
  100 
  101     home = viewmodels.Button.home(request)
  102     page = viewmodels.ErrorPage.error(button=home)
  103     t = loader.get_template(template_name)
  104 
  105     return HttpResponseBadRequest(t.render(page.context_dict()))
  106 
  107 
  108 @pageview_decorator
  109 def csrf_failure(request, reason):
  110     """
  111     View handler for CSRF_FAILURE_VIEW with custom data.
  112     """
  113     if session.active_agency(request):
  114         session.update(request, origin=session.agency(request).index_url)
  115     else:
  116         session.update(request, origin=_index_url())
  117 
  118     home = viewmodels.Button.home(request)
  119     page = viewmodels.ErrorPage.not_found(button=home, path=request.path)
  120     t = loader.get_template("400.html")
  121 
  122     return HttpResponseNotFound(t.render(page.context_dict()))
  123 
  124 
  125 @pageview_decorator
  126 def page_not_found(request, exception, template_name="404.html"):
  127     """View handler for HTTP 404 Not Found responses."""
  128     if session.active_agency(request):
  129         session.update(request, origin=session.agency(request).index_url)
  130     else:
  131         session.update(request, origin=_index_url())
  132 
  133     home = viewmodels.Button.home(request)
  134     page = viewmodels.ErrorPage.not_found(button=home, path=request.path)
  135     t = loader.get_template(template_name)
  136 
  137     return HttpResponseNotFound(t.render(page.context_dict()))
  138 
  139 
  140 @pageview_decorator
  141 def server_error(request, template_name="500.html"):
  142     """View handler for HTTP 500 Server Error responses."""
  143     if session.active_agency(request):
  144         session.update(request, origin=session.agency(request).index_url)
  145     else:
  146         session.update(request, origin=_index_url())
  147 
  148     home = viewmodels.Button.home(request)
  149     page = viewmodels.ErrorPage.error(button=home)
  150     t = loader.get_template(template_name)
  151 
  152     return HttpResponseServerError(t.render(page.context_dict()))
  153
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/benefits/core/views.py b/benefits/core/views.py
  --- a/benefits/core/views.py
  +++ b/benefits/core/views.py
  @@ -2,6 +2,7 @@
   The core application: view definition for the root of the webapp.
   """
   from django.http import HttpResponseBadRequest, HttpResponseNotFound, HttpResponseServerError
  +from django.shortcuts import redirect
   from django.template import loader
   from django.template.response import TemplateResponse
   from django.urls import reverse
  @@ -31,8 +32,13 @@
       """View handler for the main entry page."""
       session.reset(request)
   
  -    # generate a button to the landing page for each active agency
       agencies = models.TransitAgency.all_active()
  +
  +    if len(agencies) == 1:
  +        agency = agencies[0]
  +        return redirect(agency.index_url)
  +
  +    # generate a button to the landing page for each active agency
       buttons = [viewmodels.Button.outline_primary(text=a.short_name, url=a.index_url) for a in agencies]
       buttons[0].classes.append("mt-3")
       buttons[0].label = _("core.pages.index.chooseprovider")
  
verification_info: {"golden_diff": "diff --git a/benefits/core/views.py b/benefits/core/views.py\n--- a/benefits/core/views.py\n+++ b/benefits/core/views.py\n@@ -2,6 +2,7 @@\n The core application: view definition for the root of the webapp.\n \"\"\"\n from django.http import HttpResponseBadRequest, HttpResponseNotFound, HttpResponseServerError\n+from django.shortcuts import redirect\n from django.template import loader\n from django.template.response import TemplateResponse\n from django.urls import reverse\n@@ -31,8 +32,13 @@\n     \"\"\"View handler for the main entry page.\"\"\"\n     session.reset(request)\n \n-    # generate a button to the landing page for each active agency\n     agencies = models.TransitAgency.all_active()\n+\n+    if len(agencies) == 1:\n+        agency = agencies[0]\n+        return redirect(agency.index_url)\n+\n+    # generate a button to the landing page for each active agency\n     buttons = [viewmodels.Button.outline_primary(text=a.short_name, url=a.index_url) for a in agencies]\n     buttons[0].classes.append(\"mt-3\")\n     buttons[0].label = _(\"core.pages.index.chooseprovider\")\n", "issue": "Auto select Transit Agency when only 1 Active\nSimplify the flow for a user, and avoid having to deal with the design of a single button on the `core:index` page.\r\n\r\nWhen there is only 1 active transit agency, and user lands on `core:index`, forward to the active agency's `core:agency_index` page.\n", "before_files": [{"content": "\"\"\"\nThe core application: view definition for the root of the webapp.\n\"\"\"\nfrom django.http import HttpResponseBadRequest, HttpResponseNotFound, HttpResponseServerError\nfrom django.template import loader\nfrom django.template.response import TemplateResponse\nfrom django.urls import reverse\nfrom django.utils.translation import gettext as _\n\nfrom . import models, session, viewmodels\nfrom .middleware import pageview_decorator\n\n\ndef PageTemplateResponse(request, page_vm):\n    \"\"\"Helper returns a TemplateResponse using the common page template.\"\"\"\n    return TemplateResponse(request, \"core/page.html\", page_vm.context_dict())\n\n\ndef _index_content_title():\n    \"\"\"Helper returns the content title for the common index page.\"\"\"\n    return _(\"core.pages.index.content_title\")\n\n\ndef _index_url():\n    \"\"\"Helper computes the index url path.\"\"\"\n    return reverse(\"core:index\")\n\n\n@pageview_decorator\ndef index(request):\n    \"\"\"View handler for the main entry page.\"\"\"\n    session.reset(request)\n\n    # generate a button to the landing page for each active agency\n    agencies = models.TransitAgency.all_active()\n    buttons = [viewmodels.Button.outline_primary(text=a.short_name, url=a.index_url) for a in agencies]\n    buttons[0].classes.append(\"mt-3\")\n    buttons[0].label = _(\"core.pages.index.chooseprovider\")\n\n    page = viewmodels.Page(\n        title=_(\"core.pages.index.title\"),\n        content_title=_index_content_title(),\n        buttons=buttons,\n        classes=\"home\",\n    )\n\n    return PageTemplateResponse(request, page)\n\n\n@pageview_decorator\ndef agency_index(request, agency):\n    \"\"\"View handler for an agency entry page.\"\"\"\n    session.reset(request)\n    session.update(request, agency=agency, origin=agency.index_url)\n\n    button = viewmodels.Button.primary(text=_(\"core.pages.index.continue\"), url=reverse(\"eligibility:index\"))\n    button.label = _(\"core.pages.agency_index.button.label\")\n\n    page = viewmodels.Page(\n        title=_(\"core.pages.agency_index.title\"),\n        content_title=_(\"core.pages.agency_index.content_title\"),\n        button=button,\n        classes=\"home\",\n    )\n\n    help_page = reverse(\"core:help\")\n    context_dict = {**page.context_dict(), **{\"info_link\": f\"{help_page}#about\"}}\n\n    return TemplateResponse(request, \"core/agency_index.html\", context_dict)\n\n\n@pageview_decorator\ndef help(request):\n    \"\"\"View handler for the help page.\"\"\"\n    if session.active_agency(request):\n        agency = session.agency(request)\n        buttons = viewmodels.Button.agency_contact_links(agency)\n    else:\n        buttons = [btn for a in models.TransitAgency.all_active() for btn in viewmodels.Button.agency_contact_links(a)]\n\n    buttons.append(viewmodels.Button.home(request, _(\"core.buttons.back\")))\n\n    page = viewmodels.Page(\n        title=_(\"core.buttons.help\"),\n        content_title=_(\"core.buttons.help\"),\n        buttons=buttons,\n        noimage=True,\n    )\n\n    return TemplateResponse(request, \"core/help.html\", page.context_dict())\n\n\n@pageview_decorator\ndef bad_request(request, exception, template_name=\"400.html\"):\n    \"\"\"View handler for HTTP 400 Bad Request responses.\"\"\"\n    if session.active_agency(request):\n        session.update(request, origin=session.agency(request).index_url)\n    else:\n        session.update(request, origin=_index_url())\n\n    home = viewmodels.Button.home(request)\n    page = viewmodels.ErrorPage.error(button=home)\n    t = loader.get_template(template_name)\n\n    return HttpResponseBadRequest(t.render(page.context_dict()))\n\n\n@pageview_decorator\ndef csrf_failure(request, reason):\n    \"\"\"\n    View handler for CSRF_FAILURE_VIEW with custom data.\n    \"\"\"\n    if session.active_agency(request):\n        session.update(request, origin=session.agency(request).index_url)\n    else:\n        session.update(request, origin=_index_url())\n\n    home = viewmodels.Button.home(request)\n    page = viewmodels.ErrorPage.not_found(button=home, path=request.path)\n    t = loader.get_template(\"400.html\")\n\n    return HttpResponseNotFound(t.render(page.context_dict()))\n\n\n@pageview_decorator\ndef page_not_found(request, exception, template_name=\"404.html\"):\n    \"\"\"View handler for HTTP 404 Not Found responses.\"\"\"\n    if session.active_agency(request):\n        session.update(request, origin=session.agency(request).index_url)\n    else:\n        session.update(request, origin=_index_url())\n\n    home = viewmodels.Button.home(request)\n    page = viewmodels.ErrorPage.not_found(button=home, path=request.path)\n    t = loader.get_template(template_name)\n\n    return HttpResponseNotFound(t.render(page.context_dict()))\n\n\n@pageview_decorator\ndef server_error(request, template_name=\"500.html\"):\n    \"\"\"View handler for HTTP 500 Server Error responses.\"\"\"\n    if session.active_agency(request):\n        session.update(request, origin=session.agency(request).index_url)\n    else:\n        session.update(request, origin=_index_url())\n\n    home = viewmodels.Button.home(request)\n    page = viewmodels.ErrorPage.error(button=home)\n    t = loader.get_template(template_name)\n\n    return HttpResponseServerError(t.render(page.context_dict()))\n", "path": "benefits/core/views.py"}], "after_files": [{"content": "\"\"\"\nThe core application: view definition for the root of the webapp.\n\"\"\"\nfrom django.http import HttpResponseBadRequest, HttpResponseNotFound, HttpResponseServerError\nfrom django.shortcuts import redirect\nfrom django.template import loader\nfrom django.template.response import TemplateResponse\nfrom django.urls import reverse\nfrom django.utils.translation import gettext as _\n\nfrom . import models, session, viewmodels\nfrom .middleware import pageview_decorator\n\n\ndef PageTemplateResponse(request, page_vm):\n    \"\"\"Helper returns a TemplateResponse using the common page template.\"\"\"\n    return TemplateResponse(request, \"core/page.html\", page_vm.context_dict())\n\n\ndef _index_content_title():\n    \"\"\"Helper returns the content title for the common index page.\"\"\"\n    return _(\"core.pages.index.content_title\")\n\n\ndef _index_url():\n    \"\"\"Helper computes the index url path.\"\"\"\n    return reverse(\"core:index\")\n\n\n@pageview_decorator\ndef index(request):\n    \"\"\"View handler for the main entry page.\"\"\"\n    session.reset(request)\n\n    agencies = models.TransitAgency.all_active()\n\n    if len(agencies) == 1:\n        agency = agencies[0]\n        return redirect(agency.index_url)\n\n    # generate a button to the landing page for each active agency\n    buttons = [viewmodels.Button.outline_primary(text=a.short_name, url=a.index_url) for a in agencies]\n    buttons[0].classes.append(\"mt-3\")\n    buttons[0].label = _(\"core.pages.index.chooseprovider\")\n\n    page = viewmodels.Page(\n        title=_(\"core.pages.index.title\"),\n        content_title=_index_content_title(),\n        buttons=buttons,\n        classes=\"home\",\n    )\n\n    return PageTemplateResponse(request, page)\n\n\n@pageview_decorator\ndef agency_index(request, agency):\n    \"\"\"View handler for an agency entry page.\"\"\"\n    session.reset(request)\n    session.update(request, agency=agency, origin=agency.index_url)\n\n    button = viewmodels.Button.primary(text=_(\"core.pages.index.continue\"), url=reverse(\"eligibility:index\"))\n    button.label = _(\"core.pages.agency_index.button.label\")\n\n    page = viewmodels.Page(\n        title=_(\"core.pages.agency_index.title\"),\n        content_title=_(\"core.pages.agency_index.content_title\"),\n        button=button,\n        classes=\"home\",\n    )\n\n    help_page = reverse(\"core:help\")\n    context_dict = {**page.context_dict(), **{\"info_link\": f\"{help_page}#about\"}}\n\n    return TemplateResponse(request, \"core/agency_index.html\", context_dict)\n\n\n@pageview_decorator\ndef help(request):\n    \"\"\"View handler for the help page.\"\"\"\n    if session.active_agency(request):\n        agency = session.agency(request)\n        buttons = viewmodels.Button.agency_contact_links(agency)\n    else:\n        buttons = [btn for a in models.TransitAgency.all_active() for btn in viewmodels.Button.agency_contact_links(a)]\n\n    buttons.append(viewmodels.Button.home(request, _(\"core.buttons.back\")))\n\n    page = viewmodels.Page(\n        title=_(\"core.buttons.help\"),\n        content_title=_(\"core.buttons.help\"),\n        buttons=buttons,\n        noimage=True,\n    )\n\n    return TemplateResponse(request, \"core/help.html\", page.context_dict())\n\n\n@pageview_decorator\ndef bad_request(request, exception, template_name=\"400.html\"):\n    \"\"\"View handler for HTTP 400 Bad Request responses.\"\"\"\n    if session.active_agency(request):\n        session.update(request, origin=session.agency(request).index_url)\n    else:\n        session.update(request, origin=_index_url())\n\n    home = viewmodels.Button.home(request)\n    page = viewmodels.ErrorPage.error(button=home)\n    t = loader.get_template(template_name)\n\n    return HttpResponseBadRequest(t.render(page.context_dict()))\n\n\n@pageview_decorator\ndef csrf_failure(request, reason):\n    \"\"\"\n    View handler for CSRF_FAILURE_VIEW with custom data.\n    \"\"\"\n    if session.active_agency(request):\n        session.update(request, origin=session.agency(request).index_url)\n    else:\n        session.update(request, origin=_index_url())\n\n    home = viewmodels.Button.home(request)\n    page = viewmodels.ErrorPage.not_found(button=home, path=request.path)\n    t = loader.get_template(\"400.html\")\n\n    return HttpResponseNotFound(t.render(page.context_dict()))\n\n\n@pageview_decorator\ndef page_not_found(request, exception, template_name=\"404.html\"):\n    \"\"\"View handler for HTTP 404 Not Found responses.\"\"\"\n    if session.active_agency(request):\n        session.update(request, origin=session.agency(request).index_url)\n    else:\n        session.update(request, origin=_index_url())\n\n    home = viewmodels.Button.home(request)\n    page = viewmodels.ErrorPage.not_found(button=home, path=request.path)\n    t = loader.get_template(template_name)\n\n    return HttpResponseNotFound(t.render(page.context_dict()))\n\n\n@pageview_decorator\ndef server_error(request, template_name=\"500.html\"):\n    \"\"\"View handler for HTTP 500 Server Error responses.\"\"\"\n    if session.active_agency(request):\n        session.update(request, origin=session.agency(request).index_url)\n    else:\n        session.update(request, origin=_index_url())\n\n    home = viewmodels.Button.home(request)\n    page = viewmodels.ErrorPage.error(button=home)\n    t = loader.get_template(template_name)\n\n    return HttpResponseServerError(t.render(page.context_dict()))\n", "path": "benefits/core/views.py"}]}