summaryrefslogtreecommitdiff
path: root/mirrors/utils.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-04-25 01:32:57 -0500
committerDan McGee <dan@archlinux.org>2012-04-25 01:51:58 -0500
commit640e0f58645a7fd07f3c6185d9583b4d218e2468 (patch)
tree46323cbe3549b7d60a7b88eacb702522982b2a27 /mirrors/utils.py
parent20675141c340ea3d2d6d8305f8ba0950d3bf974c (diff)
Finish django countries implementation
* Add a migration to drop the old countries field. * Update all templates/views/utility methods to point at the new country field and dereference it as necessary. * Add the flags images to a few views where it makes sense. * Cleanup the download page layout quite a bit. * Bump the mirror status JSON version to 3; add country_code attribute. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'mirrors/utils.py')
-rw-r--r--mirrors/utils.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/mirrors/utils.py b/mirrors/utils.py
index aa1e9f76..728c3040 100644
--- a/mirrors/utils.py
+++ b/mirrors/utils.py
@@ -1,6 +1,7 @@
from datetime import timedelta
from django.db.models import Avg, Count, Max, Min, StdDev
+from django_countries.fields import Country
from main.utils import cache_function, utc_now
from .models import MirrorLog, MirrorProtocol, MirrorUrl
@@ -89,13 +90,14 @@ def get_mirror_errors(cutoff=default_cutoff):
errors = MirrorLog.objects.filter(
is_success=False, check_time__gte=cutoff_time,
url__mirror__active=True, url__mirror__public=True).values(
- 'url__url', 'url__country_old', 'url__protocol__protocol',
- 'url__mirror__country_old', 'error').annotate(
+ 'url__url', 'url__country', 'url__protocol__protocol',
+ 'url__mirror__country', 'error').annotate(
error_count=Count('error'), last_occurred=Max('check_time')
).order_by('-last_occurred', '-error_count')
errors = list(errors)
for err in errors:
- err['country'] = err['url__country_old'] or err['url__mirror__country_old']
+ ctry_code = err['url__country'] or err['url__mirror__country']
+ err['country'] = Country(ctry_code)
return errors
@@ -114,16 +116,15 @@ def get_mirror_url_for_download(cutoff=default_cutoff):
best_logs = MirrorLog.objects.filter(is_success=True,
check_time__gte=min_check_time, last_sync__gte=min_sync_time,
url__mirror__public=True, url__mirror__active=True,
- url__protocol__protocol__iexact='HTTP').order_by(
+ url__protocol__default=True).order_by(
'duration')[:1]
if best_logs:
return MirrorUrl.objects.get(id=best_logs[0].url_id)
mirror_urls = MirrorUrl.objects.filter(
- mirror__public=True, mirror__active=True,
- protocol__protocol__iexact='HTTP')
- # look first for an 'Any' URL, then fall back to any HTTP URL
- filtered_urls = mirror_urls.filter(mirror__country_old='Any')[:1]
+ mirror__public=True, mirror__active=True, protocol__default=True)
+ # look first for a country-agnostic URL, then fall back to any HTTP URL
+ filtered_urls = mirror_urls.filter(mirror__country='')[:1]
if not filtered_urls:
filtered_urls = mirror_urls[:1]
if not filtered_urls: