From aaa140043d68e920d8c2b4d555f3c3b3f40eda94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riku=20Kestila=CC=88?= Date: Wed, 16 Oct 2024 16:30:42 +0300 Subject: [PATCH] feat: use compact_list query parameter for csv --- .../applications/api/v1/application_views.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/backend/benefit/applications/api/v1/application_views.py b/backend/benefit/applications/api/v1/application_views.py index 264f16ea24..1079ce66b6 100755 --- a/backend/benefit/applications/api/v1/application_views.py +++ b/backend/benefit/applications/api/v1/application_views.py @@ -61,6 +61,9 @@ ApplicationAlterationCsvService, ) from applications.services.applications_csv_report import ApplicationsCsvService +from applications.services.applications_power_bi_csv_report import ( + ApplicationsPowerBiCsvService, +) from applications.services.clone_application import clone_application_based_on_other from applications.services.generate_application_summary import ( generate_application_summary_file, @@ -774,7 +777,11 @@ def with_unread_messages(self, request, *args, **kwargs): def export_csv(self, request) -> StreamingHttpResponse: queryset = self.get_queryset() filtered_queryset = self.filter_queryset(queryset) - return self._csv_response(filtered_queryset) + compact_list = ( + request.query_params.get("compact_list", "false").lower() == "true" + ) + + return self._csv_response(filtered_queryset, compact_list) APPLICATION_ORDERING = "application_number" @@ -873,12 +880,20 @@ def _csv_response( prune_data_for_talpa: bool = False, remove_quotes: bool = False, prune_sensitive_data: bool = True, + compact_list: bool = False, ) -> StreamingHttpResponse: - csv_service = ApplicationsCsvService( - queryset.order_by(self.APPLICATION_ORDERING), - prune_data_for_talpa, - prune_sensitive_data, - ) + if compact_list: + # The PowerBi service already provides a more compact list, + # so we use it here as well + csv_service = ApplicationsPowerBiCsvService( + queryset.order_by(self.APPLICATION_ORDERING), + ) + else: + csv_service = ApplicationsCsvService( + queryset.order_by(self.APPLICATION_ORDERING), + prune_data_for_talpa, + prune_sensitive_data, + ) response = StreamingHttpResponse( csv_service.get_csv_string_lines_generator(remove_quotes), content_type="text/csv",