Skip to content

Commit

Permalink
feat: use compact_list query parameter for csv
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke committed Oct 16, 2024
1 parent fed90d1 commit aaa1400
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions backend/benefit/applications/api/v1/application_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit aaa1400

Please sign in to comment.