From 574b5186de4186fbcfc3c6ab4dc4f522c39f8cb1 Mon Sep 17 00:00:00 2001 From: Evarin Date: Sun, 24 Jun 2018 22:24:24 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=A9pare=20le=20probl=C3=A8me=20avec=20les?= =?UTF-8?q?=20espaces=20et=20extensions=20de=20fichier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- partitions/views.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/partitions/views.py b/partitions/views.py index e4e9b4d..4127ea5 100644 --- a/partitions/views.py +++ b/partitions/views.py @@ -1,6 +1,7 @@ from django.shortcuts import render, HttpResponse, get_object_or_404 from django.contrib.auth.decorators import login_required from django.utils.encoding import smart_str +from django.utils.text import slugify from django.forms.models import modelform_factory from django.core.files import File from django.utils.safestring import mark_safe @@ -52,8 +53,8 @@ def see(request, nom, auteur, partition_id): myfile = File(f) response = HttpResponse(content=myfile.read()) response["Content-Type"] = "application/pdf" - response["Content-Disposition"] = "inline; filename=%s-%s-%s" % ( - nom, auteur, smart_str(os.path.basename(myfile.name))) + response["Content-Disposition"] = "inline; filename=%s_%s_%s.pdf" % ( + slugify(nom), slugify(auteur), slugify(partition.nom)) return response elif ".mp3" == extension: with open(partition.part.path, 'rb') as f: @@ -77,8 +78,8 @@ def download(request, nom, auteur, partition_id): response = HttpResponse(content=myfile.read()) typ = os.path.splitext(myfile.name)[1][1:] response['Content-Type'] = 'application/%s' % (typ, ) - response['Content-Disposition'] = 'attachment; filename=%s-%s-%s' % ( - nom, auteur, smart_str(os.path.basename(myfile.name))) + response['Content-Disposition'] = 'attachment; filename=%s_%s_%s.%s' % ( + slugify(nom), slugify(auteur), slugify(partition.nom), typ) return response