From 36ce63477b7ab677af57f3d579910fc4afd35ee2 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 11 Aug 2011 22:10:06 +0200 Subject: [PATCH] add content-disposition for download urls --- pandora/item/urls.py | 2 +- pandora/item/views.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pandora/item/urls.py b/pandora/item/urls.py index c00949863..6cc1484e4 100644 --- a/pandora/item/urls.py +++ b/pandora/item/urls.py @@ -16,7 +16,7 @@ urlpatterns = patterns("item.views", (r'^(?P[A-Z0-9].+)/(?P\d+p)(?P\d*)\.(?Pwebm|ogv|mp4)$', 'video'), #torrent - (r'^(?P[A-Z0-9][A-Za-z0-9]+)/torrent/(?P.+?)$', 'torrent'), + (r'^(?P[A-Z0-9][A-Za-z0-9]+)/torrent/(?P.*?)$', 'torrent'), #icon (r'^(?P[A-Z0-9].+)/icon(?P\d*)\.jpg$', 'icon'), diff --git a/pandora/item/views.py b/pandora/item/views.py index d94e0c3c1..ab18014ec 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -624,14 +624,17 @@ def torrent(request, id, filename=None): response = HttpFileResponse(item.torrent.path, content_type='application/x-bittorrent') filename = "%s.torrent" % item.get('title') - response['Content-Disposition'] = 'attachment; filename="%s"' % filename + response['Content-Disposition'] = 'attachment; filename="%s"' % filename.encode('utf-8') return response while filename.startswith('/'): filename = filename[1:] filename = filename.replace('/../', '/') filename = item.path('torrent/%s' % filename) filename = os.path.abspath(os.path.join(settings.MEDIA_ROOT, filename)) - return HttpFileResponse(filename) + response = HttpFileResponse(filename) + response['Content-Disposition'] = 'attachment; filename="%s"' % \ + os.path.basename(filename.encode('utf-8')) + return response def video(request, id, profile, index=None, format=None): print id, profile, index, format