summaryrefslogtreecommitdiff
path: root/packages/views.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-09-14 14:37:13 -0400
committerDan McGee <dan@archlinux.org>2011-09-14 14:37:13 -0400
commitb893682f356ca2861d676a51c4ae1c937d4c7c44 (patch)
treea38df5919a9376e0b344b998c8e380a4beafe1ed /packages/views.py
parent617550628b39f94e6cb11ec032eb18e6195bf64a (diff)
Ensure we have a mirror URL to return
If our query returned zero results, then try a slightly less exclusive query followed by returning a 404 result. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages/views.py')
-rw-r--r--packages/views.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/packages/views.py b/packages/views.py
index 8c9c1b18..79793355 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -548,15 +548,21 @@ def flag_confirmed(request, name, repo, arch):
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_urls = MirrorUrl.objects.filter(
mirror__public=True, mirror__active=True,
- protocol__protocol__iexact='HTTP')[0]
+ protocol__protocol__iexact='HTTP')
+ # look first for an 'Any' URL, then fall back to any HTTP URL
+ filtered_urls = mirror_urls.filter(mirror__country='Any')[:1]
+ if not filtered_urls:
+ filtered_urls = mirror_urls[:1]
+ if not filtered_urls:
+ raise Http404
arch = pkg.arch.name
if pkg.arch.agnostic:
# grab the first non-any arch to fake the download path
arch = Arch.objects.exclude(agnostic=True)[0].name
values = {
- 'host': mirrorurl.url,
+ 'host': filtered_urls[0].url,
'arch': arch,
'repo': pkg.repo.name.lower(),
'file': pkg.filename,