Implement API

This commit is contained in:
zandercymatics 2023-11-20 16:20:37 -07:00
parent 67f9de03d4
commit e52954f984
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 35 additions and 0 deletions

32
src/api/report_views.py Normal file
View 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