From 3dea0da4a9b3fdb63be4e197ab49a5e1d1842398 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 4 Nov 2010 14:29:50 -0500 Subject: Ensure mirrorlist generator works if no status available Saw this error come through on the live site today, as well as being reproducible when no mirror check runs have happened in the last 24 hours on a development machine. Let mirrors that have no available checks show up on this page, but be sorted last and show a score of unknown. Signed-off-by: Dan McGee --- mirrors/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mirrors/views.py b/mirrors/views.py index 93007acb..fb7d3361 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -11,7 +11,6 @@ from .utils import get_mirror_statuses, get_mirror_errors import datetime -from operator import attrgetter class MirrorlistForm(forms.Form): country = forms.MultipleChoiceField(required=False) @@ -77,10 +76,14 @@ def find_mirrors(request, countries=None, protocols=None, use_status=False, scores = dict([(u.id, u.score) for u in status_info['urls']]) urls = [] for u in qset: - u.score = scores[u.id] - if u.score and u.score < 100.0: + u.score = scores.get(u.id, None) + # also include mirrors that don't have an up to date score + # (as opposed to those that have been set with no score) + if (u.id not in scores) or \ + (u.score and u.score < 100.0): urls.append(u) - urls = sorted(urls, key=attrgetter('score')) + # if a url doesn't have a score, treat it as the highest possible + urls = sorted(urls, key=lambda x: x.score or 100.0) template = 'mirrors/mirrorlist_status.txt' return direct_to_template(request, template, { -- cgit v1.2.3-54-g00ecf