summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-05-26 17:47:43 +0200
committerDan McGee <dan@archlinux.org>2010-05-26 17:50:03 +0200
commitdebec14b736162c65421ee1bace3adb049746ed4 (patch)
tree1f532f8e36c2055ba0fb5d7372b72514b5fc6f5a
parent5866498603eb8cc7d194bff39e01a45b11ba36d3 (diff)
downloadarchweb-debec14b736162c65421ee1bace3adb049746ed4.tar.gz
archweb-debec14b736162c65421ee1bace3adb049746ed4.tar.xz
Add ability to download package from web interface
After adding filename to the database, this is a rather simple request (see FS#19546). Right now the "randomly" chosen mirror happens to always be mirrors.kernel.org as it is the only one filed under the 'Any' country which is what we screen on. Perhaps this logic could be improved in the future but I don't see these links being all that high traffic anyway. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--packages/views.py18
-rw-r--r--templates/packages/details.html1
-rw-r--r--urls.py2
3 files changed, 20 insertions, 1 deletions
diff --git a/packages/views.py b/packages/views.py
index 682dded..6838de0 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -12,9 +12,11 @@ from django.views.generic import list_detail
from django.db.models import Q
import datetime
+import string
from main.models import Package, PackageFile
from main.models import Arch, Repo, Signoff
+from main.models import MirrorUrl
from main.utils import make_choice
from packages.models import PackageRelation
@@ -316,5 +318,19 @@ def flag(request, name='', repo='', arch=''):
return render_to_response('packages/flag.html', context)
-# vim: set ts=4 sw=4 et:
+def download(request, name='', repo='', arch=''):
+ pkg = get_object_or_404(Package,
+ pkgname=name, repo__name__iexact=repo, arch__name=arch)
+ mirrorurl = MirrorUrl.objects.filter(mirror__country='Any',
+ mirror__public=True, mirror__active=True,
+ protocol__protocol__iexact='HTTP')[0]
+ details = {
+ 'host': mirrorurl.url,
+ 'arch': pkg.arch.name,
+ 'repo': pkg.repo.name.lower(),
+ 'file': pkg.filename,
+ }
+ url = string.Template('${host}${repo}/os/${arch}/${file}').substitute(details)
+ return HttpResponseRedirect(url)
+# vim: set ts=4 sw=4 et:
diff --git a/templates/packages/details.html b/templates/packages/details.html
index c7945b2..4539477 100644
--- a/templates/packages/details.html
+++ b/templates/packages/details.html
@@ -28,6 +28,7 @@
'height=350,width=450,location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=no');">(?)</a>
{% endif %}
</li>
+ <li><a href="download/" title="Download {{ pkg.pkgname }} from mirror">Download From Mirror</a></li>
</ul>
{% if user.is_authenticated %}
diff --git a/urls.py b/urls.py
index c52f6ab..8fe7d7d 100644
--- a/urls.py
+++ b/urls.py
@@ -52,6 +52,8 @@ urlpatterns = patterns('',
'packages.views.flag'),
(r'^packages/(?P<repo>[A-z0-9\-]+)/(?P<arch>[A-z0-9]+)/(?P<name>[A-z0-9\-+.]+)/unflag/$',
'packages.views.unflag'),
+ (r'^packages/(?P<repo>[A-z0-9\-]+)/(?P<arch>[A-z0-9]+)/(?P<name>[A-z0-9\-+.]+)/download/$',
+ 'packages.views.download'),
(r'^todo/(\d+)/$', 'todolists.views.view'),
(r'^todo/add/$', 'todolists.views.add'),