diff --git a/backend/benefit/applications/api/v1/application_batch_views.py b/backend/benefit/applications/api/v1/application_batch_views.py index 1aa41f2c75..011ae930fb 100755 --- a/backend/benefit/applications/api/v1/application_batch_views.py +++ b/backend/benefit/applications/api/v1/application_batch_views.py @@ -1,6 +1,6 @@ from django.db import transaction from django.forms import ValidationError -from django.http import HttpResponse, StreamingHttpResponse +from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.utils import timezone from django.utils.text import format_lazy @@ -161,11 +161,14 @@ def export_batch(self, request, *args, **kwargs): permission_classes=[AllowAny], ) @transaction.atomic - def talpa_export_batch(self, request, *args, **kwargs) -> StreamingHttpResponse: + def talpa_export_batch(self, request, *args, **kwargs) -> HttpResponse: """ Export ApplicationBatch to CSV format for Talpa Robot """ - skip_update = request.query_params.get("skip_update") == "1" + skip_update = ( + request.query_params.get("skip_update") + and request.query_params.get("skip_update") == "1" + ) approved_batches = ApplicationBatch.objects.filter( status=ApplicationBatchStatus.DECIDED_ACCEPTED @@ -189,10 +192,11 @@ def talpa_export_batch(self, request, *args, **kwargs) -> StreamingHttpResponse: date=timezone.now().strftime("%Y%m%d_%H%M%S"), ) - response = StreamingHttpResponse( - csv_service.get_csv_string_lines_generator(True, True), + response = HttpResponse( + csv_service.get_csv_string(True).encode("utf-8"), content_type="text/csv", ) + response["Content-Disposition"] = "attachment; filename={filename}.csv".format( filename=file_name ) diff --git a/backend/benefit/applications/tests/test_application_batch_api.py b/backend/benefit/applications/tests/test_application_batch_api.py index bfc5c3f2b5..6188ecb446 100755 --- a/backend/benefit/applications/tests/test_application_batch_api.py +++ b/backend/benefit/applications/tests/test_application_batch_api.py @@ -8,7 +8,7 @@ import pytz from dateutil.relativedelta import relativedelta from django.conf import settings -from django.http import StreamingHttpResponse +from django.http import HttpResponse from rest_framework.reverse import reverse from applications.api.v1.serializers.application import ApplicationBatchSerializer @@ -838,6 +838,6 @@ def test_application_batches_talpa_export(anonymous_client, application_batch): assert application_batch.status == ApplicationBatchStatus.SENT_TO_TALPA assert app_batch_2.status == ApplicationBatchStatus.SENT_TO_TALPA - assert isinstance(response, StreamingHttpResponse) + assert isinstance(response, HttpResponse) assert response.headers["Content-Type"] == "text/csv" assert response.status_code == 200