diff --git a/src/api/report_views.py b/src/api/report_views.py new file mode 100644 index 000000000..2e479a8a1 --- /dev/null +++ b/src/api/report_views.py @@ -0,0 +1,32 @@ +"""Internal API views""" +from django.apps import apps +from django.views.decorators.http import require_http_methods +from django.http import FileResponse, JsonResponse + +import requests + + +from registrar.utility import csv_export +from login_required import login_not_required + +@require_http_methods(["GET"]) +@login_not_required +def get_current_full(request): + # Generate the CSV file + with open("current-full.csv", "w") as file: + csv_export.export_data_full_to_csv(file) + + # Serve the CSV file + response = FileResponse(open('current-full.csv', 'rb')) + return response + +@require_http_methods(["GET"]) +@login_not_required +def get_current_federal(request): + # Generate the CSV file + with open("current-federal.csv", "w") as file: + csv_export.export_data_federal_to_csv(file) + + # Serve the CSV file + response = FileResponse(open('current-federal.csv', 'rb')) + return response diff --git a/src/registrar/config/urls.py b/src/registrar/config/urls.py index c00d1c589..e71f1388e 100644 --- a/src/registrar/config/urls.py +++ b/src/registrar/config/urls.py @@ -12,6 +12,7 @@ from registrar import views from registrar.views.application import Step from registrar.views.utility import always_404 from api.views import available +from api.report_views import get_current_federal, get_current_full APPLICATION_NAMESPACE = views.ApplicationWizard.URL_NAMESPACE application_urls = [ @@ -73,6 +74,8 @@ urlpatterns = [ path("openid/", include("djangooidc.urls")), path("register/", include((application_urls, APPLICATION_NAMESPACE))), path("api/v1/available/", available, name="available"), + path("api/v1/get-report/current-federal", get_current_federal, name="get-current-federal"), + path("api/v1/get-report/current-full", get_current_full, name="get-current-full"), path( "todo", lambda r: always_404(r, "We forgot to include this link, sorry."),