mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-04-29 18:32:38 +02:00
Change filename.csv to commande_<order_numver>.csv
This commit is contained in:
parent
cbc0a3b119
commit
f9d1e10a2e
2 changed files with 10 additions and 4 deletions
|
@ -287,10 +287,15 @@
|
||||||
// Download emails list
|
// Download emails list
|
||||||
function downloadEmailToCSV() {
|
function downloadEmailToCSV() {
|
||||||
fetch("{% url 'order:email_list' grouped_order.code %}?format=csv")
|
fetch("{% url 'order:email_list' grouped_order.code %}?format=csv")
|
||||||
.then(response => response.text())
|
.then(response => {
|
||||||
.then(data => {
|
const contentDisposition = response.headers.get('Content-Disposition');
|
||||||
|
const filenameMatch = contentDisposition.match(/filename="(.+)"/);
|
||||||
|
const filename = filenameMatch[1];
|
||||||
|
return response.text().then(data => ({data, filename}));
|
||||||
|
})
|
||||||
|
.then(({data, filename}) => {
|
||||||
var blob = new Blob([data], {type: "text/csv;charset=utf-8"});
|
var blob = new Blob([data], {type: "text/csv;charset=utf-8"});
|
||||||
saveAs(blob, "liste_emails.csv");
|
saveAs(blob, filename);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -338,7 +338,8 @@ class ExportGroupOrderEmailAdressesToDownloadView(UserPassesTestMixin, generic.V
|
||||||
format = self.request.GET.get("format", "json")
|
format = self.request.GET.get("format", "json")
|
||||||
if format == "csv":
|
if format == "csv":
|
||||||
response = http.HttpResponse(content_type="text/csv")
|
response = http.HttpResponse(content_type="text/csv")
|
||||||
response['Content-Disposition'] = 'attachment; filename="emails.csv"'
|
filename = f"commande _{grouped_order.name.replace(' ', '_')}"
|
||||||
|
response['Content-Disposition'] = f'attachment; filename="{filename}.csv"'
|
||||||
writer = csv.writer(response)
|
writer = csv.writer(response)
|
||||||
writer.writerow(['order_name', 'email'])
|
writer.writerow(['order_name', 'email'])
|
||||||
for email in email_list:
|
for email in email_list:
|
||||||
|
|
Loading…
Reference in a new issue