summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-07-03 02:24:54 +0200
committerDan McGee <dan@archlinux.org>2010-07-03 02:24:54 +0200
commitd29d23ecf39fe1ef4a25702618a6ab710ce191b7 (patch)
tree50c507132f02d36d35b8e2ec83af737838f75572
parent1a945dd13731ef8703b4124fda19b80f756fd5fa (diff)
downloadarchweb-d29d23ecf39fe1ef4a25702618a6ab710ce191b7.tar.gz
archweb-d29d23ecf39fe1ef4a25702618a6ab710ce191b7.tar.xz
Get mirrorlist view ready for general use
Make the page much more flexible- allow multiple countries to be selected rather than just one in the form. Also add a lot more text to the page, and move the 'all' option out into its own subheading rather than being in the same form. Both GET and POST requests are now allowed for ease of use from non-browser scenarios or those that wish to update their mirrorlist automatically and submit parameters to the URL. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--media/archweb.css3
-rw-r--r--mirrors/views.py36
-rw-r--r--templates/mirrors/index.html17
-rw-r--r--urls.py6
4 files changed, 39 insertions, 23 deletions
diff --git a/media/archweb.css b/media/archweb.css
index dc15cf6..07a050b 100644
--- a/media/archweb.css
+++ b/media/archweb.css
@@ -24,6 +24,9 @@ code { font: 1.2em monospace; background: #ffa; padding: 0.15em 0.25em; }
pre { font: 1.2em monospace; border: 1px solid #bdb; background: #dfd; padding: 0.5em; margin: 0.25em 2em; }
blockquote { margin: 1.5em 2em; }
input { vertical-align: middle; }
+select[multiple] { padding-top: 1px; padding-bottom: 1px; }
+select[multiple] option { padding-left: 0.3em; padding-right: 0.5em; }
+input[type=submit] { padding-left: 0.6em; padding-right: 0.6em; }
.clear { clear: both; }
hr { border: none; border-top: 1px solid #888; }
img { border: 0; }
diff --git a/mirrors/views.py b/mirrors/views.py
index a67a2d7..fbff697 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -1,50 +1,48 @@
from django import forms
-from django.core.urlresolvers import reverse
from django.db.models import Q
-from django.http import HttpResponseRedirect
-from django.shortcuts import get_object_or_404, render_to_response
+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.utils import make_choice
class MirrorlistForm(forms.Form):
- country = forms.ChoiceField(required=False)
+ country = forms.MultipleChoiceField(required=False)
def __init__(self, *args, **kwargs):
super(MirrorlistForm, self).__init__(*args, **kwargs)
- mirrors = Mirror.objects.values_list(
+ mirrors = Mirror.objects.filter(active=True).values_list(
'country', flat=True).distinct().order_by('country')
- self.fields['country'].choices = [('all', 'All')] + make_choice(
+ self.fields['country'].choices = make_choice(
[mirror for mirror in mirrors])
-
-def choose(request):
- if request.POST:
- form = MirrorlistForm(data=request.POST)
+@csrf_exempt
+def generate(request):
+ if request.REQUEST.get('country', ''):
+ form = MirrorlistForm(data=request.REQUEST)
if form.is_valid():
- country = form.cleaned_data['country']
- return HttpResponseRedirect(reverse(generate,
- kwargs = { 'country' : country }))
+ countries = form.cleaned_data['country']
+ return find_mirrors(request, countries)
else:
form = MirrorlistForm()
return render_to_response('mirrors/index.html', {'mirrorlist_form': form},
context_instance=RequestContext(request))
-def generate(request, country=None):
+def find_mirrors(request, countries=None):
qset = MirrorUrl.objects.select_related().filter(
Q(protocol__protocol__iexact='HTTP') |
Q(protocol__protocol__iexact='FTP'),
mirror__public=True, mirror__active=True, mirror__isos=True
)
- if country and country != 'all':
- qset = qset.filter(mirror__country__iexact=country)
+ if countries and 'all' not in countries:
+ qset = qset.filter(mirror__country__in=countries)
qset = qset.order_by('mirror__country', 'mirror__name', 'url')
- res = render_to_response('mirrors/mirrorlist.txt',
- {
+ res = render_to_response('mirrors/mirrorlist.txt', {
'mirror_urls': qset,
},
- mimetype='text/plain')
+ mimetype='text/plain',
+ context_instance=RequestContext(request))
return res
# vim: set ts=4 sw=4 et:
diff --git a/templates/mirrors/index.html b/templates/mirrors/index.html
index f386ea4..f6db74f 100644
--- a/templates/mirrors/index.html
+++ b/templates/mirrors/index.html
@@ -7,13 +7,28 @@
<h2>Pacman Mirrorlist Generator</h2>
+ <p>This page generates the most up-to-date mirrorlist possible for Arch
+ Linux. The data used here comes straight from the developers' internal
+ mirror database used to track mirror availability and tiering. There are
+ two main options: get a mirrorlist with every available mirror, or get a
+ mirrorlist tailored to your geography.</p>
+
+ <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>
+
+ <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>
- <form id="list-generator" method="post">{% csrf_token %}
+ <form id="list-generator" method="get">
{{ mirrorlist_form.as_p }}
<p><label></label> <input type="submit" value="Generate List" /></p>
</form>
diff --git a/urls.py b/urls.py
index 75de954..c8f1790 100644
--- a/urls.py
+++ b/urls.py
@@ -63,10 +63,10 @@ urlpatterns = patterns('',
(r'^news/delete/(\d+)/$', 'news.views.delete'),
(r'^news/$', 'news.views.list', {}, 'news-list'),
- (r'^mirrors/$', 'devel.views.mirrorlist'),
+ (r'^mirrors/$', 'devel.views.mirrorlist', {}, 'mirrors-list'),
- (r'^mirrorlist/$', 'mirrors.views.choose'),
- (r'^mirrorlist/(?P<country>[A-z0-9 ]+)/$', 'mirrors.views.generate'),
+ (r'^mirrorlist/$', 'mirrors.views.generate', {}, 'mirrorlist'),
+ (r'^mirrorlist/all/$', 'mirrors.views.find_mirrors', {'countries': ['all']}),
(r'^devel/$', 'devel.views.index'),
(r'^devel/notify/$', 'devel.views.change_notify'),