From d80908e21e88c78262563f5852d81f2754fb5d82 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 23 Dec 2013 09:44:08 -0600 Subject: Change import location of django_countries fields This will work with both the newer and older versions. Signed-off-by: Dan McGee --- mirrors/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mirrors') diff --git a/mirrors/models.py b/mirrors/models.py index 57664562..0b053043 100644 --- a/mirrors/models.py +++ b/mirrors/models.py @@ -5,7 +5,7 @@ from urlparse import urlparse from django.core.exceptions import ValidationError from django.db import models from django.db.models.signals import pre_save -from django_countries import CountryField +from django_countries.fields import CountryField from .fields import IPNetworkField from main.utils import set_created_field -- cgit v1.2.3-2-g168b From 5eff1ab9bf0c3820c8b90e18efee1dfc773d08fc Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 23 Dec 2013 11:51:04 -0600 Subject: Set all attributes to default values on status URL fetch We were missing two duration-related attributes here, causing some 500 errors to happen if we had cached status_data around that didn't agree with our current list of checked mirrors. Don't blow up on the JSON data fetch by ensuring we provide a value, even if it is out of date. Signed-off-by: Dan McGee --- mirrors/utils.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mirrors') diff --git a/mirrors/utils.py b/mirrors/utils.py index 0dd26ae0..be44121a 100644 --- a/mirrors/utils.py +++ b/mirrors/utils.py @@ -88,6 +88,8 @@ def annotate_url(url, url_data): ('success_count', 0), ('check_count', 0), ('completion_pct', None), + ('duration_avg', None), + ('duration_stddev', None), ('last_check', None), ('last_sync', None), ('delay', None), -- cgit v1.2.3-2-g168b From fe37b46c50b60a8302e70ccef3ab34306fd8ea39 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 11 Jan 2014 13:37:12 -0600 Subject: Add a 'last_modified' function for mirror status pages We can use this on both the HTML and JSON views of this data to prevent recomputation for smart clients that respect the modified date header. Signed-off-by: Dan McGee --- mirrors/views.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'mirrors') diff --git a/mirrors/views.py b/mirrors/views.py index 34336165..5429cea2 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -11,6 +11,7 @@ from django.http import Http404, HttpResponse from django.shortcuts import get_object_or_404, redirect, render from django.utils.timezone import now from django.views.decorators.csrf import csrf_exempt +from django.views.decorators.http import condition from django_countries.countries import COUNTRIES from .models import (Mirror, MirrorUrl, MirrorProtocol, MirrorLog, @@ -220,6 +221,11 @@ def url_details(request, name, url_id): return render(request, 'mirrors/url_details.html', context) +def status_last_modified(request, *args, **kwargs): + return MirrorLog.objects.values_list('check_time', flat=True).latest() + + +@condition(last_modified_func=status_last_modified) def status(request, tier=None): if tier is not None: tier = int(tier) @@ -297,6 +303,7 @@ class ExtendedMirrorStatusJSONEncoder(MirrorStatusJSONEncoder): return super(ExtendedMirrorStatusJSONEncoder, self).default(obj) +@condition(last_modified_func=status_last_modified) def status_json(request, tier=None): if tier is not None: tier = int(tier) -- cgit v1.2.3-2-g168b From 16b22e4bfc2e271a58a79a9fb4ccb5e059c6d62a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 22 Feb 2014 08:49:58 -0600 Subject: Upgrade django-countries to 2.0 Signed-off-by: Dan McGee --- mirrors/migrations/0015_assign_country_codes.py | 4 ++-- mirrors/utils.py | 2 +- mirrors/views.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'mirrors') diff --git a/mirrors/migrations/0015_assign_country_codes.py b/mirrors/migrations/0015_assign_country_codes.py index c1b0f969..5d83e02c 100644 --- a/mirrors/migrations/0015_assign_country_codes.py +++ b/mirrors/migrations/0015_assign_country_codes.py @@ -4,12 +4,12 @@ from south.db import db from south.v2 import DataMigration from django.db import models -from django_countries.countries import OFFICIAL_COUNTRIES +from django_countries.data import COUNTRIES class Migration(DataMigration): def forwards(self, orm): - reverse_map = dict((v, k) for k, v in OFFICIAL_COUNTRIES.items()) + reverse_map = dict((v.upper(), k) for k, v in COUNTRIES.items()) # add a few special cases to the list that we know might exist reverse_map['GREAT BRITAIN'] = 'GB' reverse_map['KOREA'] = 'KR' diff --git a/mirrors/utils.py b/mirrors/utils.py index be44121a..fe18cd6a 100644 --- a/mirrors/utils.py +++ b/mirrors/utils.py @@ -179,7 +179,7 @@ def get_mirror_errors(cutoff=DEFAULT_CUTOFF, mirror_id=None, show_all=False): errors = list(errors) for err in errors: - err['country'] = Country(err['url__country']) + err['country'] = Country(err['url__country'], flag_url='') return errors diff --git a/mirrors/views.py b/mirrors/views.py index 5429cea2..26b5b802 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -12,7 +12,7 @@ from django.shortcuts import get_object_or_404, redirect, render from django.utils.timezone import now from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import condition -from django_countries.countries import COUNTRIES +from django_countries.data import COUNTRIES from .models import (Mirror, MirrorUrl, MirrorProtocol, MirrorLog, CheckLocation) -- cgit v1.2.3-2-g168b