Repository: cisagov/manage.get.gov

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 


Discussion:
Here's a sketch of how this could look:
![New Drawing 15](https://github.com/cisagov/getgov/assets/13547334/5180aaf3-b926-46a8-bdc5-e48590683106)

Excellent! The only thing this is missing is the publication of current-federal.csv and current-full.csv at a public URL. Added at #1075.

I've re-added the refinement label so the product leads to ensure the A/C are clear.

Resolving patch:
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 @@ def export_data_type_to_csv(csv_file):
         "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 @@ def export_data_full_to_csv(csv_file):
         "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 @@ def export_data_federal_to_csv(csv_file):
         "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": [


Test patch: