summaryrefslogtreecommitdiff
path: root/mirrors/views.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-05-02 12:23:21 -0500
committerDan McGee <dan@archlinux.org>2012-05-02 12:23:21 -0500
commitd2d0895f13835569ff25a3161ddb94cd655dfd4f (patch)
treef50d51b7495c08eb7e365cd44126e54e325ce35e /mirrors/views.py
parent768bc688aab844cf9fdf9809b9381aaf0042f2fc (diff)
Allow mirrorlist generator pattern to match any protocol
Add a helper method that checks if we know about the protocol; if so, we can spit out a URL for it. This allows (if you are insane) generation of an rsync mirrorlist, for instance. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'mirrors/views.py')
-rw-r--r--mirrors/views.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/mirrors/views.py b/mirrors/views.py
index c52656f7..6f37ace1 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -82,12 +82,15 @@ def generate_mirrorlist(request):
def find_mirrors(request, countries=None, protocols=None, use_status=False,
ipv4_supported=True, ipv6_supported=True):
if not protocols:
- protocols = MirrorProtocol.objects.filter(
- is_download=True).values_list('protocol', flat=True)
+ protocols = MirrorProtocol.objects.filter(is_download=True)
+ elif hasattr(protocols, 'model') and protocols.model == MirrorProtocol:
+ # we already have a queryset, no need to query again
+ pass
+ else:
+ protocols = MirrorProtocol.objects.filter(protocol__in=protocols)
qset = MirrorUrl.objects.select_related().filter(
- protocol__protocol__in=protocols,
- mirror__public=True, mirror__active=True,
- )
+ protocol__in=protocols,
+ mirror__public=True, mirror__active=True)
if countries and 'all' not in countries:
qset = qset.filter(Q(country__in=countries) |
Q(mirror__country__in=countries))
@@ -124,6 +127,11 @@ def find_mirrors(request, countries=None, protocols=None, use_status=False,
mimetype='text/plain')
+def find_mirrors_simple(request, protocol):
+ proto = get_object_or_404(MirrorProtocol, protocol=protocol)
+ return find_mirrors(request, protocols=[proto])
+
+
def mirrors(request):
mirror_list = Mirror.objects.select_related().order_by('tier', 'country')
if not request.user.is_authenticated():