Skip to content

Commit

Permalink
testing returning path file in s3
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJaeger committed Jul 14, 2023
1 parent 32f8bee commit d472de2
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions chats/apps/api/v1/dashboard/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from chats.apps.projects.models import Project
from io import BytesIO
import io
from chats.core.excel_storage import ExcelStorage
import json



class DashboardLiveViewset(viewsets.GenericViewSet):
Expand Down Expand Up @@ -170,8 +173,6 @@ def export_dashboard(self, request, *args, **kwargs):
data_frame_1 = pandas.DataFrame(userinfo_dataset)
data_frame_2 = pandas.DataFrame(sector_dataset)

excel_file = BytesIO()

if "xls" in filter:
excel_buffer = io.BytesIO()
with pandas.ExcelWriter(excel_buffer, engine="xlsxwriter") as writer:
Expand All @@ -196,27 +197,21 @@ def export_dashboard(self, request, *args, **kwargs):
startcol=0,
index=False,
)
print("antes do seek\n", excel_buffer.getvalue())
print(
"------------------------------------------------------------------------------------------------------"
)
print(
"------------------------------------------------------------------------------------------------------"
)
print(
"------------------------------------------------------------------------------------------------------"
)
excel_buffer.seek(0) # Move o cursor para o início do buffer
print("depois do seek:\n", excel_buffer.getvalue())
storage = ExcelStorage()

response = HttpResponse(
excel_buffer.read(),
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
)
response["Content-Disposition"] = (
'attachment; filename="' + filename + '.xlsx"'
bytes_archive = excel_buffer.getvalue()

with storage.open(filename, "wb") as up_file:
up_file.write(bytes_archive)
file_url = storage.url(up_file.name)

data = {"path_file": file_url}

return HttpResponse(
json.dumps(data),
content_type="application/javascript; charset=utf8",
)
return response

else:
response = HttpResponse(content_type="text/csv")
Expand Down

0 comments on commit d472de2

Please sign in to comment.