mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-26 12:38:36 +02:00
Implement API
This commit is contained in:
parent
67f9de03d4
commit
e52954f984
2 changed files with 35 additions and 0 deletions
32
src/api/report_views.py
Normal file
32
src/api/report_views.py
Normal file
|
@ -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
|
|
@ -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/<domain>", 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."),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue