refactor: use provide_binary_file
This commit is contained in:
parent
839de22d95
commit
433b285b92
3 changed files with 9 additions and 22 deletions
|
|
@ -432,23 +432,20 @@ class DataExporter:
|
|||
row[_column_start_end.start + i + 1] = value
|
||||
|
||||
def build_response_as_excel(self):
|
||||
from frappe.desk.utils import provide_binary_file
|
||||
from frappe.utils.xlsxutils import make_xlsx
|
||||
|
||||
filename = frappe.generate_hash(length=10)
|
||||
with open(filename, "wb") as f:
|
||||
f.write(cstr(self.writer.getvalue()).encode("utf-8"))
|
||||
f = open(filename)
|
||||
reader = csv.reader(f)
|
||||
|
||||
from frappe.utils.xlsxutils import make_xlsx
|
||||
|
||||
xlsx_file = make_xlsx(reader, "Data Import Template" if self.template else "Data Export")
|
||||
|
||||
f.close()
|
||||
os.remove(filename)
|
||||
|
||||
# write out response as a xlsx type
|
||||
frappe.response["filename"] = self.doctype + ".xlsx"
|
||||
frappe.response["filecontent"] = xlsx_file.getvalue()
|
||||
frappe.response["type"] = "binary"
|
||||
provide_binary_file(self.doctype, "xlsx", xlsx_file.getvalue())
|
||||
|
||||
def _append_name_column(self, dt=None):
|
||||
self.append_field_column(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
import typing
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model import display_fieldtypes, no_value_fields
|
||||
|
|
@ -241,15 +239,9 @@ class Exporter:
|
|||
|
||||
def build_response(self):
|
||||
if self.file_type == "CSV":
|
||||
self.build_csv_response()
|
||||
build_csv_response(self.get_csv_array_for_export(), _(self.doctype))
|
||||
elif self.file_type == "Excel":
|
||||
self.build_xlsx_response()
|
||||
|
||||
def build_csv_response(self):
|
||||
build_csv_response(self.get_csv_array_for_export(), _(self.doctype))
|
||||
|
||||
def build_xlsx_response(self):
|
||||
build_xlsx_response(self.get_csv_array_for_export(), _(self.doctype))
|
||||
build_xlsx_response(self.get_csv_array_for_export(), _(self.doctype))
|
||||
|
||||
def group_children_data_by_parent(self, children_data: dict[str, list]):
|
||||
return groupby_metric(children_data, key="parent")
|
||||
|
|
|
|||
|
|
@ -108,8 +108,6 @@ def read_xls_file_from_attached_file(content):
|
|||
|
||||
|
||||
def build_xlsx_response(data, filename):
|
||||
xlsx_file = make_xlsx(data, filename)
|
||||
# write out response as a xlsx type
|
||||
frappe.response["filename"] = filename + ".xlsx"
|
||||
frappe.response["filecontent"] = xlsx_file.getvalue()
|
||||
frappe.response["type"] = "binary"
|
||||
from frappe.desk.utils import provide_binary_file
|
||||
|
||||
provide_binary_file(filename, "xlsx", make_xlsx(data, filename).getvalue())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue