From bc5a5781bf43f81ab266bf258d4ab8bf16c9b2d0 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 23 Sep 2010 18:50:56 -0500 Subject: Add a basic mirror details page Still some work to do here, but this covers the basics of the public view we can show for mirrors and their associated data. The upstream and downstream links should be working OK to aid navigation, but right now we have some potential dead links for non-authenticated users if they click a link to a "private" mirror. Signed-off-by: Dan McGee --- mirrors/models.py | 6 ++++ mirrors/views.py | 11 +++++++ templates/mirrors/mirror_details.html | 58 +++++++++++++++++++++++++++++++++++ templates/mirrors/mirrors.html | 3 +- urls.py | 1 + 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 templates/mirrors/mirror_details.html diff --git a/mirrors/models.py b/mirrors/models.py index d8d1a3e5..85423303 100644 --- a/mirrors/models.py +++ b/mirrors/models.py @@ -31,6 +31,12 @@ class Mirror(models.Model): urls__mirror=self).order_by('protocol').distinct() return ", ".join([p.protocol for p in protocols]) + def downstream(self): + return Mirror.objects.filter(upstream=self).order_by('name') + + def get_absolute_url(self): + return '/mirrors/%s/' % self.name + class MirrorProtocol(models.Model): protocol = models.CharField(max_length=10, unique=True) def __unicode__(self): diff --git a/mirrors/views.py b/mirrors/views.py index 9380f810..34385a98 100644 --- a/mirrors/views.py +++ b/mirrors/views.py @@ -1,6 +1,8 @@ from django import forms from django.db.models import Avg, Count, Max, Min, StdDev from django.db.models import Q +from django.http import Http404 +from django.shortcuts import get_object_or_404 from django.views.decorators.csrf import csrf_exempt from django.views.generic.simple import direct_to_template @@ -77,6 +79,15 @@ def mirrors(request): return direct_to_template(request, 'mirrors/mirrors.html', {'mirror_list': mirrors}) +def mirror_details(request, name): + mirror = get_object_or_404(Mirror, name=name) + if not request.user.is_authenticated() and \ + (not mirror.public or not mirror.active): + # TODO: maybe this should be 403? but that would leak existence + raise Http404 + return direct_to_template(request, 'mirrors/mirror_details.html', + {'mirror': mirror}) + def status(request): bad_timedelta = datetime.timedelta(days=3) status_info = get_mirror_statuses() diff --git a/templates/mirrors/mirror_details.html b/templates/mirrors/mirror_details.html new file mode 100644 index 00000000..90baa75d --- /dev/null +++ b/templates/mirrors/mirror_details.html @@ -0,0 +1,58 @@ +{% extends "base.html" %} + +{% block title %}Arch Linux - {{ mirror.name }} - Mirror Details{% endblock %} + +{% block content %} + +
+ +

Mirror Details: {{ mirror.name }}

+ + + + + + + + + + + + + + + {% with mirror.downstream as ds_mirrors %} + + {% endwith %} + + + + + + + + + + + + {% with mirror.urls.all as urls %} + + {% endwith %} + +
Name:{{ mirror.name }}
Tier:{{ mirror.get_tier_display }}
Upstream:{% if mirror.upstream %} + {{ mirror.upstream.name }} + {% else %}None{% endif %}
Downstream:{% if ds_mirrors %} + {% for ds in ds_mirrors %} + {{ ds.name }}
+ {% endfor %} + {% else %}None{% endif %} +
Country:{{ mirror.country }}
Has ISOs:{{ mirror.isos|yesno }}
Protocols:{{ mirror.supported_protocols }}
Mirror URLs:{% if urls %} + {% for u in urls %} + {{ u.url }}
+ {% endfor %} + {% else %}None{% endif %} +
+
+{% endblock %} diff --git a/templates/mirrors/mirrors.html b/templates/mirrors/mirrors.html index 253efe53..56f23db5 100644 --- a/templates/mirrors/mirrors.html +++ b/templates/mirrors/mirrors.html @@ -24,7 +24,8 @@ {% for mirror in mirror_list %} - {{mirror.name}} + {{ mirror.name }} {{mirror.get_tier_display}} {{mirror.country}} {{mirror.isos|yesno}} diff --git a/urls.py b/urls.py index dde7abba..5c792035 100644 --- a/urls.py +++ b/urls.py @@ -73,6 +73,7 @@ urlpatterns = patterns('', (r'^mirrors/$', 'mirrors.views.mirrors', {}, 'mirrors-list'), (r'^mirrors/status/$', 'mirrors.views.status', {}, 'mirror-status'), + (r'^mirrors/(?P[\.\-\w]+)/$', 'mirrors.views.mirror_details'), (r'^mirrorlist/$', 'mirrors.views.generate_mirrorlist', {}, 'mirrorlist'), (r'^mirrorlist/all/$', 'mirrors.views.find_mirrors', {'countries': ['all']}), -- cgit v1.2.3-55-g3dc8