From f6af4111f528ec86966eea5662cf94172bf1cdb1 Mon Sep 17 00:00:00 2001 From: Eduard0803 Date: Wed, 6 Dec 2023 15:03:16 -0300 Subject: [PATCH] add index in report --- gestao/web/api/document/utils.py | 2 ++ gestao/web/api/document/views.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gestao/web/api/document/utils.py b/gestao/web/api/document/utils.py index 0930c15..89aed99 100644 --- a/gestao/web/api/document/utils.py +++ b/gestao/web/api/document/utils.py @@ -5,6 +5,7 @@ def generate_report_users_file(all_users_list: list, filter_list: list): template_data = { + "index": [], "fullName": [], "warName": [], "registration": [], @@ -38,6 +39,7 @@ def generate_report_users_file(all_users_list: list, filter_list: list): } for user in all_users_list: + template_data["index"].append(all_users_list.index(user) + 1) template_data["fullName"].append(user.fullName) template_data["warName"].append(user.warName) template_data["registration"].append(user.registration) diff --git a/gestao/web/api/document/views.py b/gestao/web/api/document/views.py index 21834d0..f7f2868 100644 --- a/gestao/web/api/document/views.py +++ b/gestao/web/api/document/views.py @@ -10,12 +10,16 @@ @router.get("/report-users/") -async def get_report_users(filter_list: List[str]): +async def get_report_users(filter_list: List[str] = []): users_list = await User.objects.all() file_stream = generate_report_users_file(list(users_list), filter_list) + file_name = "report-users.xlsx" return StreamingResponse( file_stream, media_type=( "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ), + headers={ + "Content-Disposition": f"attachment; filename={file_name}", + }, )