Suppression de chemins hardcodés
- Dans la vue `partitions.views.download`, les chemins vers les sont calculés à partir des infos dans la BDD - Le templatetag `cuturl` obsolète est supprimé
This commit is contained in:
parent
7d242674f3
commit
0ce3299adb
6 changed files with 12 additions and 23 deletions
|
@ -1,9 +0,0 @@
|
||||||
from django import template
|
|
||||||
|
|
||||||
register = template.Library()
|
|
||||||
|
|
||||||
@register.filter
|
|
||||||
def cuturl(texte):
|
|
||||||
tex = texte.split('/')
|
|
||||||
n = len(tex)
|
|
||||||
return tex[n-1]
|
|
|
@ -7,7 +7,7 @@ urlpatterns = patterns('partitions.views',
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/delete/?$', 'delete_morc'),
|
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/delete/?$', 'delete_morc'),
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/conf/?$', 'conf_delete_morc'),
|
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/conf/?$', 'conf_delete_morc'),
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/see/(?P<partition_id>\d+)/?$', 'see'),
|
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/see/(?P<partition_id>\d+)/?$', 'see'),
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<file_name>[^/]+)/$', 'download'),
|
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<partition_id>\d+)/$', 'download'),
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<id>[^/]+)/delete/?$', 'delete'),
|
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<id>[^/]+)/delete/?$', 'delete'),
|
||||||
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<id>[^/]+)/conf/?$', 'conf_delete'),
|
url(r'^(?P<nom>[^/]+)/(?P<auteur>[^/]+)/(?P<id>[^/]+)/conf/?$', 'conf_delete'),
|
||||||
url(r'^new/?$', 'ajouter_morceau'),
|
url(r'^new/?$', 'ajouter_morceau'),
|
||||||
|
|
|
@ -55,7 +55,7 @@ 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" % (
|
||||||
nom, auteur, smart_str(os.path.basename(myfile.name)))
|
nom, auteur, smart_str(os.path.basename(myfile.name)))
|
||||||
return response
|
return response
|
||||||
elif ".mp3" == extension:
|
elif ".mp3" == extension:
|
||||||
|
@ -72,15 +72,15 @@ def see(request, nom, auteur, partition_id):
|
||||||
return render(request, 'partitions/listepart.html', locals())
|
return render(request, 'partitions/listepart.html', locals())
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def download(request, nom, auteur, file_name):
|
def download(request, nom, auteur, partition_id):
|
||||||
abspath=open('/var/www_new/media/partitions/' + file_name, 'rb')
|
partition = get_object_or_404(Partition, id=partition_id)
|
||||||
response = HttpResponse(content=abspath.read())
|
with open(partition.part.path, 'rb') as f:
|
||||||
typ = file_name.split(".")
|
myfile = File(f)
|
||||||
n = len(typ)
|
response = HttpResponse(content=myfile.read())
|
||||||
typ = typ[n-1]
|
typ = os.path.splitext(myfile.name)[1][1:]
|
||||||
response['Content-Type'] = 'application/' + typ
|
response['Content-Type'] = 'application/%s' % (typ, )
|
||||||
response['Content-Disposition'] = 'attachment; filename= %s ' % (nom +'-'+ auteur + '-' + smart_str(file_name))
|
response['Content-Disposition'] = 'attachment; filename=%s-%s-%s' % (
|
||||||
abspath.close()
|
nom, auteur, smart_str(os.path.basename(myfile.name)))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
{% load static %}
|
{% load static %}
|
||||||
{% load urls_extra %}
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load urls_extra %}
|
|
||||||
|
|
||||||
{% block titre %}{{ p }}{% endblock %}
|
{% block titre %}{{ p }}{% endblock %}
|
||||||
|
|
||||||
|
@ -38,7 +37,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<a href="{% url "partitions.views.download" nom auteur p.part.url|cuturl %}" class="telecharger">Télécharger</a>
|
<a href="{% url "partitions.views.download" nom auteur p.id %}" class="telecharger">Télécharger</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if user.profile.is_chef %}
|
{% if user.profile.is_chef %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue