summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2013-01-19 17:38:54 -0600
committerDan McGee <dan@archlinux.org>2013-01-19 17:40:26 -0600
commitb642c93aff6bd22013615ae8b51b7a02763e261c (patch)
tree97155528ace995c55bda91fdaa39fc316c729e16
parent4d52242f4b5a20a591b5bd44cc0dc12f15a9c92c (diff)
Add a view to download the torrent available for a given release
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--releng/urls.py15
-rw-r--r--releng/views.py16
2 files changed, 26 insertions, 5 deletions
diff --git a/releng/urls.py b/releng/urls.py
index 8413d318..76c36345 100644
--- a/releng/urls.py
+++ b/releng/urls.py
@@ -11,11 +11,18 @@ feedback_patterns = patterns('releng.views',
(r'^iso/overview/$', 'iso_overview', {}, 'releng-iso-overview'),
)
-urlpatterns = patterns('',
- (r'^feedback/', include(feedback_patterns)),
- (r'^releases/$',
+releases_patterns = patterns('releng.views',
+ (r'^$',
ReleaseListView.as_view(), {}, 'releng-release-list'),
- (r'^releases/(?P<version>[-.\w]+)/$',
+ (r'^(?P<version>[-.\w]+)/$',
ReleaseDetailView.as_view(), {}, 'releng-release-detail'),
+ (r'^(?P<version>[-.\w]+)/torrent/$',
+ 'release_torrent', {}, 'releng-release-torrent'),
)
+
+urlpatterns = patterns('',
+ (r'^feedback/', include(feedback_patterns)),
+ (r'^releases/', include(releases_patterns)),
+)
+
# vim: set ts=4 sw=4 et:
diff --git a/releng/views.py b/releng/views.py
index 6c49275f..ad4b07d1 100644
--- a/releng/views.py
+++ b/releng/views.py
@@ -1,7 +1,9 @@
+from base64 import b64decode
+
from django import forms
from django.conf import settings
from django.db.models import Count, Max
-from django.http import Http404
+from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.views.generic import DetailView, ListView
@@ -224,4 +226,16 @@ class ReleaseDetailView(DetailView):
slug_field = 'version'
slug_url_kwarg = 'version'
+
+def release_torrent(request, version):
+ release = get_object_or_404(Release, version=version)
+ if not release.torrent_data:
+ raise Http404
+ data = b64decode(release.torrent_data)
+ response = HttpResponse(data, content_type='application/x-bittorrent')
+ # TODO: this is duplicated from Release.iso_url()
+ filename = 'archlinux-%s-dual.iso.torrent' % release.version
+ response['Content-Disposition'] = 'attachment; filename=%s' % filename
+ return response
+
# vim: set ts=4 sw=4 et: