summaryrefslogtreecommitdiff
path: root/mirrors
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-04-15 17:15:17 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-04-15 17:15:17 -0400
commit86bd3d5e4920fd6d57ac51ed3abf02d2f368f2a7 (patch)
tree7d2f4688eafc26e5ce821d576a4028e986b70f10 /mirrors
parent7a8b5707b277f052b712c51574b0e28834b5a5f8 (diff)
parent5bfe138a86a98b52f0b6746b900af6431cd4d17a (diff)
Merge tag 'release_2014-11-02' into archweb-generic
Staff groups
Diffstat (limited to 'mirrors')
-rw-r--r--mirrors/admin.py2
-rw-r--r--mirrors/migrations/0002_mirrorurl_bandwidth.py20
-rw-r--r--mirrors/models.py3
-rw-r--r--mirrors/views.py37
4 files changed, 49 insertions, 13 deletions
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 @@ from .models import (Mirror, MirrorProtocol, MirrorUrl, MirrorRsync,
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'
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 @@ import json
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.utils.timezone import now
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 @@ from .utils import get_mirror_statuses, get_mirror_errors, DEFAULT_CUTOFF
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 @@ class MirrorlistForm(forms.Form):
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 <divs>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})