diff options
Diffstat (limited to 'mirrors')
-rw-r--r-- | mirrors/views.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/mirrors/views.py b/mirrors/views.py index fbff697d..aaafc1be 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: |