mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
ListExporter: Allow to override CSV encoding in subclass (Z#23160604) (#4367)
This commit is contained in:
@@ -207,10 +207,13 @@ class ListExporter(BaseExporter):
|
|||||||
def get_filename(self):
|
def get_filename(self):
|
||||||
return 'export'
|
return 'export'
|
||||||
|
|
||||||
|
def get_csv_encoding(self):
|
||||||
|
return 'utf-8'
|
||||||
|
|
||||||
def _render_csv(self, form_data, output_file=None, **kwargs):
|
def _render_csv(self, form_data, output_file=None, **kwargs):
|
||||||
if output_file:
|
if output_file:
|
||||||
if 'b' in output_file.mode:
|
if 'b' in output_file.mode:
|
||||||
output_file = io.TextIOWrapper(output_file, encoding='utf-8', newline='')
|
output_file = io.TextIOWrapper(output_file, encoding=self.get_csv_encoding(), errors='replace', newline='')
|
||||||
writer = csv.writer(output_file, **kwargs)
|
writer = csv.writer(output_file, **kwargs)
|
||||||
total = 0
|
total = 0
|
||||||
counter = 0
|
counter = 0
|
||||||
@@ -246,7 +249,7 @@ class ListExporter(BaseExporter):
|
|||||||
if counter % max(10, total // 100) == 0:
|
if counter % max(10, total // 100) == 0:
|
||||||
self.progress_callback(counter / total * 100)
|
self.progress_callback(counter / total * 100)
|
||||||
writer.writerow(line)
|
writer.writerow(line)
|
||||||
return self.get_filename() + '.csv', 'text/csv', output.getvalue().encode("utf-8")
|
return self.get_filename() + '.csv', 'text/csv', output.getvalue().encode(self.get_csv_encoding(), errors='replace')
|
||||||
|
|
||||||
def prepare_xlsx_sheet(self, ws):
|
def prepare_xlsx_sheet(self, ws):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user