Répare le problème avec les espaces et extensions de fichier
This commit is contained in:
parent
217e644db3
commit
574b5186de
1 changed files with 5 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
from django.shortcuts import render, HttpResponse, get_object_or_404
|
from django.shortcuts import render, HttpResponse, get_object_or_404
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
|
from django.utils.text import slugify
|
||||||
from django.forms.models import modelform_factory
|
from django.forms.models import modelform_factory
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
@ -52,8 +53,8 @@ def see(request, nom, auteur, partition_id):
|
||||||
myfile = File(f)
|
myfile = File(f)
|
||||||
response = HttpResponse(content=myfile.read())
|
response = HttpResponse(content=myfile.read())
|
||||||
response["Content-Type"] = "application/pdf"
|
response["Content-Type"] = "application/pdf"
|
||||||
response["Content-Disposition"] = "inline; filename=%s-%s-%s" % (
|
response["Content-Disposition"] = "inline; filename=%s_%s_%s.pdf" % (
|
||||||
nom, auteur, smart_str(os.path.basename(myfile.name)))
|
slugify(nom), slugify(auteur), slugify(partition.nom))
|
||||||
return response
|
return response
|
||||||
elif ".mp3" == extension:
|
elif ".mp3" == extension:
|
||||||
with open(partition.part.path, 'rb') as f:
|
with open(partition.part.path, 'rb') as f:
|
||||||
|
@ -77,8 +78,8 @@ def download(request, nom, auteur, partition_id):
|
||||||
response = HttpResponse(content=myfile.read())
|
response = HttpResponse(content=myfile.read())
|
||||||
typ = os.path.splitext(myfile.name)[1][1:]
|
typ = os.path.splitext(myfile.name)[1][1:]
|
||||||
response['Content-Type'] = 'application/%s' % (typ, )
|
response['Content-Type'] = 'application/%s' % (typ, )
|
||||||
response['Content-Disposition'] = 'attachment; filename=%s-%s-%s' % (
|
response['Content-Disposition'] = 'attachment; filename=%s_%s_%s.%s' % (
|
||||||
nom, auteur, smart_str(os.path.basename(myfile.name)))
|
slugify(nom), slugify(auteur), slugify(partition.nom), typ)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue