Mp3 en ligne
This commit is contained in:
parent
da7d41965f
commit
04bdb4d2e3
2 changed files with 10 additions and 1 deletions
|
@ -3,7 +3,6 @@ from django.contrib.auth.decorators import login_required
|
|||
from django.utils.encoding import smart_str
|
||||
|
||||
import os
|
||||
from reportlab.pdfgen import canvas
|
||||
|
||||
|
||||
from partitions.forms import UploadFileForm, UploadMorceauForm
|
||||
|
@ -49,6 +48,14 @@ def see(request, nom, auteur, file_name):
|
|||
response["Content-Disposition"]="inline; filename= %s" % (nom +'-'+ auteur +'-' + smart_str(file_name))
|
||||
abspath.close()
|
||||
return response
|
||||
elif ".mp3" in file_name:
|
||||
abspath=open('/home/rikm/Projets/Ernesto/media/partitions/' + file_name, 'rb')
|
||||
response = HttpResponse()
|
||||
response.write(abspath.read())
|
||||
response["Content-Type"]="audio/mp3"
|
||||
response["Content-Length"]= os.path.getsize('/home/rikm/Projets/Ernesto/media/partitions/' + file_name)
|
||||
abspath.close()
|
||||
return response
|
||||
else:
|
||||
partitions = PartitionSet.objects.get(nom=nom, auteur=auteur)
|
||||
part = partitions.partition_set.all()
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
{% for p in part %}
|
||||
{% if user.is_authenticated and ".pdf" in p.part.url %}
|
||||
<p><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}">{{ p.nom }}</a>
|
||||
{% elif user.is_authenticated and ".mp3" in p.part.url %}
|
||||
<p><a href="{% url "partitions.views.see" nom auteur p.part.url|cuturl %}">{{ p.nom }}</a>
|
||||
{% else %}<p>{{ p.nom }}
|
||||
{% endif %}
|
||||
{% if user.is_authenticated %}<a href="{% url "partitions.views.download" nom auteur p.part.url|cuturl %}">Télécharger</a>{% endif %} </p>
|
||||
|
|
Loading…
Reference in a new issue