From 2d407d9c1b2149d96fd3296923520aa966f9b561 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 2 Jul 2010 20:02:26 -0500 Subject: mirrorlist: allow filtering by protocol And add some more "static" URLs to access the non-country filtered lists. Signed-off-by: Dan McGee --- mirrors/views.py | 22 +++++++++++++++------- templates/mirrors/index.html | 19 ++++++++++++------- urls.py | 4 ++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/mirrors/views.py b/mirrors/views.py index fbff697..aaafc1b 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -3,18 +3,22 @@ from django.db.models import Q from django.shortcuts import render_to_response from django.template import RequestContext from django.views.decorators.csrf import csrf_exempt -from main.models import Mirror, MirrorUrl +from main.models import Mirror, MirrorUrl, MirrorProtocol from main.utils import make_choice class MirrorlistForm(forms.Form): country = forms.MultipleChoiceField(required=False) + protocol = forms.MultipleChoiceField(required=False) def __init__(self, *args, **kwargs): super(MirrorlistForm, self).__init__(*args, **kwargs) mirrors = Mirror.objects.filter(active=True).values_list( 'country', flat=True).distinct().order_by('country') - self.fields['country'].choices = make_choice( - [mirror for mirror in mirrors]) + self.fields['country'].choices = make_choice(mirrors) + protos = make_choice( + MirrorProtocol.objects.exclude(protocol__iexact='rsync')) + self.fields['protocol'].choices = protos + self.fields['protocol'].initial = [t[0] for t in protos] @csrf_exempt def generate(request): @@ -22,17 +26,21 @@ def generate(request): form = MirrorlistForm(data=request.REQUEST) if form.is_valid(): countries = form.cleaned_data['country'] - return find_mirrors(request, countries) + protocols = form.cleaned_data['protocol'] + return find_mirrors(request, countries, protocols) else: form = MirrorlistForm() return render_to_response('mirrors/index.html', {'mirrorlist_form': form}, context_instance=RequestContext(request)) -def find_mirrors(request, countries=None): +def find_mirrors(request, countries=None, protocols=None): + print 'protocols', protocols + if not protocols: + protocols = MirrorProtocol.objects.exclude( + protocol__iexact='rsync').values_list('protocol', flat=True) qset = MirrorUrl.objects.select_related().filter( - Q(protocol__protocol__iexact='HTTP') | - Q(protocol__protocol__iexact='FTP'), + protocol__protocol__in=protocols, mirror__public=True, mirror__active=True, mirror__isos=True ) if countries and 'all' not in countries: diff --git a/templates/mirrors/index.html b/templates/mirrors/index.html index f6db74f..8c193ba 100644 --- a/templates/mirrors/index.html +++ b/templates/mirrors/index.html @@ -15,18 +15,23 @@

Mirrorlist with all available mirrors

-

You can get an up-to-date - mirrorlist containing all available mirrors. - This URL requires no GET or POST parameters so can be fetched from the - command line if desired.

+

An up-to-date mirrorlist is available containing all currently active + mirrors, optionally filtering by protocol. These URLs requires no GET or + POST parameters so they can be fetched from the command line if desired.

+ +

Customized by country mirrorlist

The following form can generate a custom up-to-date pacman mirrorlist based on geography. - Simply replace the contents of /etc/pacman.d/mirrorlist with - the generated code.

+ title="ArchWiki: Pacman">pacman mirrorlist based on geography and + desired protocol(s). Simply replace the contents of + /etc/pacman.d/mirrorlist with your generated list.

{{ mirrorlist_form.as_p }} diff --git a/urls.py b/urls.py index c8f1790..2a625e5 100644 --- a/urls.py +++ b/urls.py @@ -67,6 +67,10 @@ urlpatterns = patterns('', (r'^mirrorlist/$', 'mirrors.views.generate', {}, 'mirrorlist'), (r'^mirrorlist/all/$', 'mirrors.views.find_mirrors', {'countries': ['all']}), + (r'^mirrorlist/all/ftp/$', 'mirrors.views.find_mirrors', + {'countries': ['all'], 'protocols': ['ftp']}), + (r'^mirrorlist/all/http/$', 'mirrors.views.find_mirrors', + {'countries': ['all'], 'protocols': ['http']}), (r'^devel/$', 'devel.views.index'), (r'^devel/notify/$', 'devel.views.change_notify'), -- cgit v1.2.3-24-g4f1b