prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Implement basic reporting functionality for MVP (besides Domain Growth report)
  ### Story
  
  As an Admin, I want to quickly export domain data reports directly from the domains page (/admin/registrar/domain/) so that I can easily access and analyze the domain data.
  
  ### Acceptance Criteria
  
  - [ ] Three reports are available to download on the domains page:
    - [ ] [Domains by type](https://docs.google.com/spreadsheets/d/1_nMU2obW22U6NlOSC2ARxf3PpsJnSe2wMo5AyLSzXzk/edit?usp=sharing) (sorted by domain name)
    - [ ] [current-full.csv](https://github.com/cisagov/dotgov-data/blob/main/current-full.csv) (sorted by domain name, then agency, then domain type)
    - [ ] [current-federal.csv](https://github.com/cisagov/dotgov-data/blob/main/current-federal.csv) (sorted by domain name, then agency, then domain type)
  - [ ] Each CSV report should contain accurate and up-to-date domain data from the database, sorted in the ways they are in the examples above.
  - [ ] Single dropdown with the three report options which the user can select
  - [ ] Clicking on each report triggers an immediate download of the relevant CSV report
  - [ ] The UI components should be consistent with the existing design language of the admin portal.
  
  ### Additional Context
  
  - This feature is a stop-gap measure, meant to provide immediate access to crucial reports while the ideal report interface is being developed. Future work is at #997.
  
  - Security email may be pulled from .gov database rather than thru EPP call to registry.
  
  ### Issue Links
  
  🔄 Relates to: #938 #143 #1075 
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/registrar/utility/csv_export.py`
  Content:
  ```
  1 import csv
  2 from registrar.models.domain import Domain
  3 from registrar.models.domain_information import DomainInformation
  4 from registrar.models.public_contact import PublicContact
  5 
  6 
  7 def export_domains_to_writer(writer, columns, sort_fields, filter_condition):
  8     # write columns headers to writer
  9     writer.writerow(columns)
  10 
  11     domainInfos = DomainInformation.objects.filter(**filter_condition).order_by(
  12         *sort_fields
  13     )
  14     for domainInfo in domainInfos:
  15         security_contacts = domainInfo.domain.contacts.filter(
  16             contact_type=PublicContact.ContactTypeChoices.SECURITY
  17         )
  18 
  19         # create a dictionary of fields which can be included in output
  20         FIELDS = {
  21             "Domain name": domainInfo.domain.name,
  22             "Domain type": domainInfo.get_organization_type_display()
  23             + " - "
  24             + domainInfo.get_federal_type_display()
  25             if domainInfo.federal_type
  26             else domainInfo.get_organization_type_display(),
  27             "Agency": domainInfo.federal_agency,
  28             "Organization name": domainInfo.organization_name,
  29             "City": domainInfo.city,
  30             "State": domainInfo.state_territory,
  31             "AO": domainInfo.authorizing_official.first_name
  32             + " "
  33             + domainInfo.authorizing_official.last_name
  34             if domainInfo.authorizing_official
  35             else " ",
  36             "AO email": domainInfo.authorizing_official.email
  37             if domainInfo.authorizing_official
  38             else " ",
  39             "Security Contact Email": security_contacts[0].email
  40             if security_contacts
  41             else " ",
  42             "Status": domainInfo.domain.state,
  43             "Expiration Date": domainInfo.domain.expiration_date,
  44         }
  45         writer.writerow([FIELDS.get(column, "") for column in columns])
  46 
  47 
  48 def export_data_type_to_csv(csv_file):
  49     writer = csv.writer(csv_file)
  50     # define columns to include in export
  51     columns = [
  52         "Domain name",
  53         "Domain type",
  54         "Agency",
  55         "Organization name",
  56         "City",
  57         "State",
  58         "AO",
  59         "AO email",
  60         "Security Contact Email",
  61         "Status",
  62         "Expiration Date",
  63     ]
  64     sort_fields = ["domain__name"]
  65     filter_condition = {
  66         "domain__state__in": [
  67             Domain.State.READY,
  68             Domain.State.DNS_NEEDED,
  69             Domain.State.ON_HOLD,
  70         ],
  71     }
  72     export_domains_to_writer(writer, columns, sort_fields, filter_condition)
  73 
  74 
  75 def export_data_full_to_csv(csv_file):
  76     writer = csv.writer(csv_file)
  77     # define columns to include in export
  78     columns = [
  79         "Domain name",
  80         "Domain type",
  81         "Agency",
  82         "Organization name",
  83         "City",
  84         "State",
  85         "Security Contact Email",
  86     ]
  87     sort_fields = ["domain__name", "federal_agency", "organization_type"]
  88     filter_condition = {
  89         "domain__state__in": [
  90             Domain.State.READY,
  91             Domain.State.DNS_NEEDED,
  92             Domain.State.ON_HOLD,
  93         ],
  94     }
  95     export_domains_to_writer(writer, columns, sort_fields, filter_condition)
  96 
  97 
  98 def export_data_federal_to_csv(csv_file):
  99     writer = csv.writer(csv_file)
  100     # define columns to include in export
  101     columns = [
  102         "Domain name",
  103         "Domain type",
  104         "Agency",
  105         "Organization name",
  106         "City",
  107         "State",
  108         "Security Contact Email",
  109     ]
  110     sort_fields = ["domain__name", "federal_agency", "organization_type"]
  111     filter_condition = {
  112         "organization_type__icontains": "federal",
  113         "domain__state__in": [
  114             Domain.State.READY,
  115             Domain.State.DNS_NEEDED,
  116             Domain.State.ON_HOLD,
  117         ],
  118     }
  119     export_domains_to_writer(writer, columns, sort_fields, filter_condition)
  120
  ```
  --- 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/src/registrar/utility/csv_export.py b/src/registrar/utility/csv_export.py
  --- a/src/registrar/utility/csv_export.py
  +++ b/src/registrar/utility/csv_export.py
  @@ -2,6 +2,8 @@
   from registrar.models.domain import Domain
   from registrar.models.domain_information import DomainInformation
   from registrar.models.public_contact import PublicContact
  +from django.db.models import Value
  +from django.db.models.functions import Coalesce
   
   
   def export_domains_to_writer(writer, columns, sort_fields, filter_condition):
  @@ -61,7 +63,13 @@
           "Status",
           "Expiration Date",
       ]
  -    sort_fields = ["domain__name"]
  +    # Coalesce is used to replace federal_type of None with ZZZZZ
  +    sort_fields = [
  +        "organization_type",
  +        Coalesce("federal_type", Value("ZZZZZ")),
  +        "federal_agency",
  +        "domain__name",
  +    ]
       filter_condition = {
           "domain__state__in": [
               Domain.State.READY,
  @@ -84,7 +92,13 @@
           "State",
           "Security Contact Email",
       ]
  -    sort_fields = ["domain__name", "federal_agency", "organization_type"]
  +    # Coalesce is used to replace federal_type of None with ZZZZZ
  +    sort_fields = [
  +        "organization_type",
  +        Coalesce("federal_type", Value("ZZZZZ")),
  +        "federal_agency",
  +        "domain__name",
  +    ]
       filter_condition = {
           "domain__state__in": [
               Domain.State.READY,
  @@ -107,7 +121,13 @@
           "State",
           "Security Contact Email",
       ]
  -    sort_fields = ["domain__name", "federal_agency", "organization_type"]
  +    # Coalesce is used to replace federal_type of None with ZZZZZ
  +    sort_fields = [
  +        "organization_type",
  +        Coalesce("federal_type", Value("ZZZZZ")),
  +        "federal_agency",
  +        "domain__name",
  +    ]
       filter_condition = {
           "organization_type__icontains": "federal",
           "domain__state__in": [
  
verification_info: {"golden_diff": "diff --git a/src/registrar/utility/csv_export.py b/src/registrar/utility/csv_export.py\n--- a/src/registrar/utility/csv_export.py\n+++ b/src/registrar/utility/csv_export.py\n@@ -2,6 +2,8 @@\n from registrar.models.domain import Domain\n from registrar.models.domain_information import DomainInformation\n from registrar.models.public_contact import PublicContact\n+from django.db.models import Value\n+from django.db.models.functions import Coalesce\n \n \n def export_domains_to_writer(writer, columns, sort_fields, filter_condition):\n@@ -61,7 +63,13 @@\n         \"Status\",\n         \"Expiration Date\",\n     ]\n-    sort_fields = [\"domain__name\"]\n+    # Coalesce is used to replace federal_type of None with ZZZZZ\n+    sort_fields = [\n+        \"organization_type\",\n+        Coalesce(\"federal_type\", Value(\"ZZZZZ\")),\n+        \"federal_agency\",\n+        \"domain__name\",\n+    ]\n     filter_condition = {\n         \"domain__state__in\": [\n             Domain.State.READY,\n@@ -84,7 +92,13 @@\n         \"State\",\n         \"Security Contact Email\",\n     ]\n-    sort_fields = [\"domain__name\", \"federal_agency\", \"organization_type\"]\n+    # Coalesce is used to replace federal_type of None with ZZZZZ\n+    sort_fields = [\n+        \"organization_type\",\n+        Coalesce(\"federal_type\", Value(\"ZZZZZ\")),\n+        \"federal_agency\",\n+        \"domain__name\",\n+    ]\n     filter_condition = {\n         \"domain__state__in\": [\n             Domain.State.READY,\n@@ -107,7 +121,13 @@\n         \"State\",\n         \"Security Contact Email\",\n     ]\n-    sort_fields = [\"domain__name\", \"federal_agency\", \"organization_type\"]\n+    # Coalesce is used to replace federal_type of None with ZZZZZ\n+    sort_fields = [\n+        \"organization_type\",\n+        Coalesce(\"federal_type\", Value(\"ZZZZZ\")),\n+        \"federal_agency\",\n+        \"domain__name\",\n+    ]\n     filter_condition = {\n         \"organization_type__icontains\": \"federal\",\n         \"domain__state__in\": [\n", "issue": "Implement basic reporting functionality for MVP (besides Domain Growth report)\n### Story\r\n\r\nAs an Admin, I want to quickly export domain data reports directly from the domains page (/admin/registrar/domain/) so that I can easily access and analyze the domain data.\r\n\r\n### Acceptance Criteria\r\n\r\n- [ ] Three reports are available to download on the domains page:\r\n  - [ ] [Domains by type](https://docs.google.com/spreadsheets/d/1_nMU2obW22U6NlOSC2ARxf3PpsJnSe2wMo5AyLSzXzk/edit?usp=sharing) (sorted by domain name)\r\n  - [ ] [current-full.csv](https://github.com/cisagov/dotgov-data/blob/main/current-full.csv) (sorted by domain name, then agency, then domain type)\r\n  - [ ] [current-federal.csv](https://github.com/cisagov/dotgov-data/blob/main/current-federal.csv) (sorted by domain name, then agency, then domain type)\r\n- [ ] Each CSV report should contain accurate and up-to-date domain data from the database, sorted in the ways they are in the examples above.\r\n- [ ] Single dropdown with the three report options which the user can select\r\n- [ ] Clicking on each report triggers an immediate download of the relevant CSV report\r\n- [ ] The UI components should be consistent with the existing design language of the admin portal.\r\n\r\n### Additional Context\r\n\r\n- This feature is a stop-gap measure, meant to provide immediate access to crucial reports while the ideal report interface is being developed. Future work is at #997.\r\n\r\n- Security email may be pulled from .gov database rather than thru EPP call to registry.\r\n\r\n### Issue Links\r\n\r\n\ud83d\udd04 Relates to: #938 #143 #1075 \n", "before_files": [{"content": "import csv\nfrom registrar.models.domain import Domain\nfrom registrar.models.domain_information import DomainInformation\nfrom registrar.models.public_contact import PublicContact\n\n\ndef export_domains_to_writer(writer, columns, sort_fields, filter_condition):\n    # write columns headers to writer\n    writer.writerow(columns)\n\n    domainInfos = DomainInformation.objects.filter(**filter_condition).order_by(\n        *sort_fields\n    )\n    for domainInfo in domainInfos:\n        security_contacts = domainInfo.domain.contacts.filter(\n            contact_type=PublicContact.ContactTypeChoices.SECURITY\n        )\n\n        # create a dictionary of fields which can be included in output\n        FIELDS = {\n            \"Domain name\": domainInfo.domain.name,\n            \"Domain type\": domainInfo.get_organization_type_display()\n            + \" - \"\n            + domainInfo.get_federal_type_display()\n            if domainInfo.federal_type\n            else domainInfo.get_organization_type_display(),\n            \"Agency\": domainInfo.federal_agency,\n            \"Organization name\": domainInfo.organization_name,\n            \"City\": domainInfo.city,\n            \"State\": domainInfo.state_territory,\n            \"AO\": domainInfo.authorizing_official.first_name\n            + \" \"\n            + domainInfo.authorizing_official.last_name\n            if domainInfo.authorizing_official\n            else \" \",\n            \"AO email\": domainInfo.authorizing_official.email\n            if domainInfo.authorizing_official\n            else \" \",\n            \"Security Contact Email\": security_contacts[0].email\n            if security_contacts\n            else \" \",\n            \"Status\": domainInfo.domain.state,\n            \"Expiration Date\": domainInfo.domain.expiration_date,\n        }\n        writer.writerow([FIELDS.get(column, \"\") for column in columns])\n\n\ndef export_data_type_to_csv(csv_file):\n    writer = csv.writer(csv_file)\n    # define columns to include in export\n    columns = [\n        \"Domain name\",\n        \"Domain type\",\n        \"Agency\",\n        \"Organization name\",\n        \"City\",\n        \"State\",\n        \"AO\",\n        \"AO email\",\n        \"Security Contact Email\",\n        \"Status\",\n        \"Expiration Date\",\n    ]\n    sort_fields = [\"domain__name\"]\n    filter_condition = {\n        \"domain__state__in\": [\n            Domain.State.READY,\n            Domain.State.DNS_NEEDED,\n            Domain.State.ON_HOLD,\n        ],\n    }\n    export_domains_to_writer(writer, columns, sort_fields, filter_condition)\n\n\ndef export_data_full_to_csv(csv_file):\n    writer = csv.writer(csv_file)\n    # define columns to include in export\n    columns = [\n        \"Domain name\",\n        \"Domain type\",\n        \"Agency\",\n        \"Organization name\",\n        \"City\",\n        \"State\",\n        \"Security Contact Email\",\n    ]\n    sort_fields = [\"domain__name\", \"federal_agency\", \"organization_type\"]\n    filter_condition = {\n        \"domain__state__in\": [\n            Domain.State.READY,\n            Domain.State.DNS_NEEDED,\n            Domain.State.ON_HOLD,\n        ],\n    }\n    export_domains_to_writer(writer, columns, sort_fields, filter_condition)\n\n\ndef export_data_federal_to_csv(csv_file):\n    writer = csv.writer(csv_file)\n    # define columns to include in export\n    columns = [\n        \"Domain name\",\n        \"Domain type\",\n        \"Agency\",\n        \"Organization name\",\n        \"City\",\n        \"State\",\n        \"Security Contact Email\",\n    ]\n    sort_fields = [\"domain__name\", \"federal_agency\", \"organization_type\"]\n    filter_condition = {\n        \"organization_type__icontains\": \"federal\",\n        \"domain__state__in\": [\n            Domain.State.READY,\n            Domain.State.DNS_NEEDED,\n            Domain.State.ON_HOLD,\n        ],\n    }\n    export_domains_to_writer(writer, columns, sort_fields, filter_condition)\n", "path": "src/registrar/utility/csv_export.py"}], "after_files": [{"content": "import csv\nfrom registrar.models.domain import Domain\nfrom registrar.models.domain_information import DomainInformation\nfrom registrar.models.public_contact import PublicContact\nfrom django.db.models import Value\nfrom django.db.models.functions import Coalesce\n\n\ndef export_domains_to_writer(writer, columns, sort_fields, filter_condition):\n    # write columns headers to writer\n    writer.writerow(columns)\n\n    domainInfos = DomainInformation.objects.filter(**filter_condition).order_by(\n        *sort_fields\n    )\n    for domainInfo in domainInfos:\n        security_contacts = domainInfo.domain.contacts.filter(\n            contact_type=PublicContact.ContactTypeChoices.SECURITY\n        )\n\n        # create a dictionary of fields which can be included in output\n        FIELDS = {\n            \"Domain name\": domainInfo.domain.name,\n            \"Domain type\": domainInfo.get_organization_type_display()\n            + \" - \"\n            + domainInfo.get_federal_type_display()\n            if domainInfo.federal_type\n            else domainInfo.get_organization_type_display(),\n            \"Agency\": domainInfo.federal_agency,\n            \"Organization name\": domainInfo.organization_name,\n            \"City\": domainInfo.city,\n            \"State\": domainInfo.state_territory,\n            \"AO\": domainInfo.authorizing_official.first_name\n            + \" \"\n            + domainInfo.authorizing_official.last_name\n            if domainInfo.authorizing_official\n            else \" \",\n            \"AO email\": domainInfo.authorizing_official.email\n            if domainInfo.authorizing_official\n            else \" \",\n            \"Security Contact Email\": security_contacts[0].email\n            if security_contacts\n            else \" \",\n            \"Status\": domainInfo.domain.state,\n            \"Expiration Date\": domainInfo.domain.expiration_date,\n        }\n        writer.writerow([FIELDS.get(column, \"\") for column in columns])\n\n\ndef export_data_type_to_csv(csv_file):\n    writer = csv.writer(csv_file)\n    # define columns to include in export\n    columns = [\n        \"Domain name\",\n        \"Domain type\",\n        \"Agency\",\n        \"Organization name\",\n        \"City\",\n        \"State\",\n        \"AO\",\n        \"AO email\",\n        \"Security Contact Email\",\n        \"Status\",\n        \"Expiration Date\",\n    ]\n    # Coalesce is used to replace federal_type of None with ZZZZZ\n    sort_fields = [\n        \"organization_type\",\n        Coalesce(\"federal_type\", Value(\"ZZZZZ\")),\n        \"federal_agency\",\n        \"domain__name\",\n    ]\n    filter_condition = {\n        \"domain__state__in\": [\n            Domain.State.READY,\n            Domain.State.DNS_NEEDED,\n            Domain.State.ON_HOLD,\n        ],\n    }\n    export_domains_to_writer(writer, columns, sort_fields, filter_condition)\n\n\ndef export_data_full_to_csv(csv_file):\n    writer = csv.writer(csv_file)\n    # define columns to include in export\n    columns = [\n        \"Domain name\",\n        \"Domain type\",\n        \"Agency\",\n        \"Organization name\",\n        \"City\",\n        \"State\",\n        \"Security Contact Email\",\n    ]\n    # Coalesce is used to replace federal_type of None with ZZZZZ\n    sort_fields = [\n        \"organization_type\",\n        Coalesce(\"federal_type\", Value(\"ZZZZZ\")),\n        \"federal_agency\",\n        \"domain__name\",\n    ]\n    filter_condition = {\n        \"domain__state__in\": [\n            Domain.State.READY,\n            Domain.State.DNS_NEEDED,\n            Domain.State.ON_HOLD,\n        ],\n    }\n    export_domains_to_writer(writer, columns, sort_fields, filter_condition)\n\n\ndef export_data_federal_to_csv(csv_file):\n    writer = csv.writer(csv_file)\n    # define columns to include in export\n    columns = [\n        \"Domain name\",\n        \"Domain type\",\n        \"Agency\",\n        \"Organization name\",\n        \"City\",\n        \"State\",\n        \"Security Contact Email\",\n    ]\n    # Coalesce is used to replace federal_type of None with ZZZZZ\n    sort_fields = [\n        \"organization_type\",\n        Coalesce(\"federal_type\", Value(\"ZZZZZ\")),\n        \"federal_agency\",\n        \"domain__name\",\n    ]\n    filter_condition = {\n        \"organization_type__icontains\": \"federal\",\n        \"domain__state__in\": [\n            Domain.State.READY,\n            Domain.State.DNS_NEEDED,\n            Domain.State.ON_HOLD,\n        ],\n    }\n    export_domains_to_writer(writer, columns, sort_fields, filter_condition)\n", "path": "src/registrar/utility/csv_export.py"}]}