summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-07-03 03:02:26 +0200
committerDan McGee <dan@archlinux.org>2010-07-03 03:02:26 +0200
commit2d407d9c1b2149d96fd3296923520aa966f9b561 (patch)
treea20575fa32838f0e909f9ae399fc60f2f1402934
parent67159fed20d36307fad760ba7fad00c6defc6dfc (diff)
downloadarchweb-2d407d9c1b2149d96fd3296923520aa966f9b561.tar.gz
archweb-2d407d9c1b2149d96fd3296923520aa966f9b561.tar.xz
mirrorlist: allow filtering by protocol
And add some more "static" URLs to access the non-country filtered lists. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--mirrors/views.py22
-rw-r--r--templates/mirrors/index.html19
-rw-r--r--urls.py4
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 @@
<h3>Mirrorlist with all available mirrors</h3>
- <p>You can get an up-to-date
- <a href="all/">mirrorlist containing all available mirrors</a>.
- This URL requires no GET or POST parameters so can be fetched from the
- command line if desired.<p>
+ <p>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.<p>
+
+ <ul>
+ <li><a href="all/">All mirrors</a></li>
+ <li><a href="all/ftp/">All mirrors, FTP only</a></li>
+ <li><a href="all/http/">All mirrors, HTTP only</a></li>
+ </ul>
<h3>Customized by country mirrorlist</h3>
<p>The following form can generate a custom up-to-date
<a href="http://wiki.archlinux.org/index.php/Pacman"
- title="ArchWiki: Pacman">pacman</a> mirrorlist based on geography.
- Simply replace the contents of <code>/etc/pacman.d/mirrorlist</code> with
- the generated code.</p>
+ title="ArchWiki: Pacman">pacman</a> mirrorlist based on geography and
+ desired protocol(s). Simply replace the contents of
+ <code>/etc/pacman.d/mirrorlist</code> with your generated list.</p>
<form id="list-generator" method="get">
{{ 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'),