summaryrefslogtreecommitdiff
path: root/mirrors/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'mirrors/views.py')
-rw-r--r--mirrors/views.py36
1 files changed, 17 insertions, 19 deletions
diff --git a/mirrors/views.py b/mirrors/views.py
index a67a2d7c..fbff697d 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: