From e609552c59d05a41b98e786047d1ff02c1e3ab10 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 1 Nov 2014 12:31:52 -0500 Subject: Add bandwidth field to mirror URLs Not using this anywhere just yet, but suggested by Florian so we can do some more fancy things down the road, like determine bandwidth by country. Signed-off-by: Dan McGee --- mirrors/admin.py | 2 +- mirrors/migrations/0002_mirrorurl_bandwidth.py | 20 ++++++++++++++++++++ mirrors/models.py | 3 ++- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 mirrors/migrations/0002_mirrorurl_bandwidth.py (limited to 'mirrors') diff --git a/mirrors/admin.py b/mirrors/admin.py index d5c89c2a..16a97ea2 100644 --- a/mirrors/admin.py +++ b/mirrors/admin.py @@ -11,7 +11,7 @@ class MirrorUrlForm(forms.ModelForm): class Meta: model = MirrorUrl - fields = ('url', 'country', 'active') + fields = ('url', 'country', 'bandwidth', 'active') def clean_url(self): # is this a valid-looking URL? diff --git a/mirrors/migrations/0002_mirrorurl_bandwidth.py b/mirrors/migrations/0002_mirrorurl_bandwidth.py new file mode 100644 index 00000000..f0118199 --- /dev/null +++ b/mirrors/migrations/0002_mirrorurl_bandwidth.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('mirrors', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='mirrorurl', + name='bandwidth', + field=models.FloatField(null=True, verbose_name=b'bandwidth (mbits)', blank=True), + preserve_default=True, + ), + ] diff --git a/mirrors/models.py b/mirrors/models.py index 641a6b97..820f3328 100644 --- a/mirrors/models.py +++ b/mirrors/models.py @@ -72,8 +72,9 @@ class MirrorUrl(models.Model): editable=False) has_ipv6 = models.BooleanField("IPv6 capable", default=False, editable=False) - created = models.DateTimeField(editable=False) active = models.BooleanField(default=True) + bandwidth = models.FloatField("bandwidth (mbits)", null=True, blank=True) + created = models.DateTimeField(editable=False) class Meta: verbose_name = 'mirror URL' -- cgit v1.2.3-54-g00ecf From 0c72812fde64f3ed039d807b9e8b3914960b7d6b Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 2 Nov 2014 09:42:52 -0600 Subject: Mirror view tweaks and enhancements * Add country column to main mirror list overview page. Most mirrors are strictly in one country, so do a little magic to show the right country if it makes sense. * Use new way of getting country names so we respect the overrides now present in the django_countries package. * Make the country selection box on the mirrorlist generation page a lot taller by default so it is easier to use. Signed-off-by: Dan McGee --- main/templatetags/flags.py | 2 +- mirrors/views.py | 37 ++++++++++++++++++++++++++----------- settings.py | 5 +++++ templates/mirrors/mirrors.html | 8 +++++++- 4 files changed, 39 insertions(+), 13 deletions(-) (limited to 'mirrors') diff --git a/main/templatetags/flags.py b/main/templatetags/flags.py index 22f524ca..5b356561 100644 --- a/main/templatetags/flags.py +++ b/main/templatetags/flags.py @@ -8,6 +8,6 @@ def country_flag(country): if not country: return '' return ' ' % ( - country.code.lower(), country.name) + unicode(country.code).lower(), unicode(country.name)) # vim: set ts=4 sw=4 et: diff --git a/mirrors/views.py b/mirrors/views.py index cffafbf5..65fa0123 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -4,7 +4,7 @@ from operator import attrgetter, itemgetter from django import forms -from django.forms.widgets import CheckboxSelectMultiple +from django.forms.widgets import SelectMultiple, CheckboxSelectMultiple from django.core.serializers.json import DjangoJSONEncoder from django.db import connection from django.db.models import Q @@ -14,7 +14,8 @@ from django.views.decorators.cache import cache_page from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import condition -from django_countries.data import COUNTRIES +from django_countries import countries +from django_countries.fields import Country from .models import (Mirror, MirrorUrl, MirrorProtocol, MirrorLog, CheckLocation) @@ -22,7 +23,8 @@ class MirrorlistForm(forms.Form): - country = forms.MultipleChoiceField(required=False) + country = forms.MultipleChoiceField(required=False, + widget=SelectMultiple(attrs={'size': '12'})) protocol = forms.MultipleChoiceField(required=False, widget=CheckboxSelectMultiple) ip_version = forms.MultipleChoiceField(required=False, @@ -30,8 +32,6 @@ class MirrorlistForm(forms.Form): widget=CheckboxSelectMultiple) use_mirror_status = forms.BooleanField(required=False) - countries = dict(COUNTRIES) - def __init__(self, *args, **kwargs): super(MirrorlistForm, self).__init__(*args, **kwargs) fields = self.fields @@ -49,8 +49,8 @@ def get_countries(self): country_codes.update(MirrorUrl.objects.filter(active=True, mirror__active=True).exclude(country='').values_list( 'country', flat=True).order_by().distinct()) - countries = [(code, self.countries[code]) for code in country_codes] - return sorted(countries, key=itemgetter(1)) + code_list = [(code, countries.name(code)) for code in country_codes] + return sorted(code_list, key=itemgetter(1)) def as_div(self): "Returns this form rendered as HTML s." @@ -142,14 +142,29 @@ def mirrors(request): mirror_list = Mirror.objects.select_related().order_by('tier', 'name') protos = MirrorUrl.objects.values_list( 'mirror_id', 'protocol__protocol').order_by( - 'mirror__id', 'protocol__protocol').distinct() + 'mirror_id', 'protocol__protocol').distinct() + countries = MirrorUrl.objects.values_list( + 'mirror_id', 'country').order_by( + 'mirror_id', 'country').distinct() + if not request.user.is_authenticated(): mirror_list = mirror_list.filter(public=True, active=True) - protos = protos.filter(mirror__public=True, mirror__active=True) + protos = protos.filter( + mirror__public=True, mirror__active=True, active=True) + countries = countries.filter( + mirror__public=True, mirror__active=True, active=True) + protos = {k: list(v) for k, v in groupby(protos, key=itemgetter(0))} + countries = {k: list(v) for k, v in groupby(countries, key=itemgetter(0))} + for mirror in mirror_list: - items = protos.get(mirror.id, []) - mirror.protocols = [item[1] for item in items] + item_protos = protos.get(mirror.id, []) + mirror.protocols = [item[1] for item in item_protos] + mirror.country = None + item_countries = countries.get(mirror.id, []) + if len(item_countries) == 1: + mirror.country = Country(item_countries[0][1]) + return render(request, 'mirrors/mirrors.html', {'mirror_list': mirror_list}) diff --git a/settings.py b/settings.py index ba6c68ee..60fe71bc 100644 --- a/settings.py +++ b/settings.py @@ -175,6 +175,11 @@ 'http://tracker.archlinux.org:6969/announce', ) +# Country name overrides for display purposes +COUNTRIES_OVERRIDE = { + 'MK': 'Macedonia', +} + ## Import local settings from local_settings import * diff --git a/templates/mirrors/mirrors.html b/templates/mirrors/mirrors.html index 4276b30a..f55bd875 100644 --- a/templates/mirrors/mirrors.html +++ b/templates/mirrors/mirrors.html @@ -1,8 +1,12 @@ {% extends "base.html" %} {% load cycle from future %} {% load static from staticfiles %} +{% load flags %} + {% block title %}Arch Linux - Mirror Overview{% endblock %} +{% block head %}{% endblock %} + {% block content %}

Mirror Overview

@@ -10,6 +14,7 @@

Mirror Overview

Server + Country Tier ISOs Protocols @@ -26,6 +31,7 @@

Mirror Overview

{{ mirror.name }} + {% if mirror.country %}{% country_flag mirror.country %}{{ mirror.country.name }}{% else %}Various{% endif %} {{ mirror.get_tier_display }} {{ mirror.isos|yesno|capfirst }} {{ mirror.protocols|join:", " }} @@ -44,7 +50,7 @@

Mirror Overview

{% endblock %} -- cgit v1.2.3-54-g00ecf