summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2013-01-14 15:54:33 +0100
committerDan McGee <dan@archlinux.org>2013-01-14 15:54:33 +0100
commit0f6a0a1cd0011c8ad137a4b27d0b39a7e1129fb7 (patch)
tree1b9a1aa70d0e85b29c18166a38398a9c83b8a4f6
parentff6db38f1dc6ed1eb53454a7e16615ec1ad76d7a (diff)
downloadarchweb-0f6a0a1cd0011c8ad137a4b27d0b39a7e1129fb7.tar.gz
archweb-0f6a0a1cd0011c8ad137a4b27d0b39a7e1129fb7.tar.xz
Support mirror status JSON by tier
Just as we do for the normal status HTML view. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--mirrors/urls.py1
-rw-r--r--mirrors/views.py8
2 files changed, 8 insertions, 1 deletions
diff --git a/mirrors/urls.py b/mirrors/urls.py
index 857e99e..4e92941 100644
--- a/mirrors/urls.py
+++ b/mirrors/urls.py
@@ -5,6 +5,7 @@ urlpatterns = patterns('mirrors.views',
(r'^status/$', 'status', {}, 'mirror-status'),
(r'^status/json/$', 'status_json', {}, 'mirror-status-json'),
(r'^status/tier/(?P<tier>\d+)/$', 'status', {}, 'mirror-status-tier'),
+ (r'^status/tier/(?P<tier>\d+)/json/$', 'status_json', {}, 'mirror-status-tier-json'),
(r'^(?P<name>[\.\-\w]+)/$', 'mirror_details'),
(r'^(?P<name>[\.\-\w]+)/json/$', 'mirror_details_json'),
)
diff --git a/mirrors/views.py b/mirrors/views.py
index 30df547..c0ed667 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -279,9 +279,15 @@ class ExtendedMirrorStatusJSONEncoder(MirrorStatusJSONEncoder):
return super(ExtendedMirrorStatusJSONEncoder, self).default(obj)
-def status_json(request):
+def status_json(request, tier=None):
+ if tier is not None:
+ tier = int(tier)
+ if tier not in [t[0] for t in Mirror.TIER_CHOICES]:
+ raise Http404
status_info = get_mirror_statuses()
data = status_info.copy()
+ if tier is not None:
+ data['urls'] = [url for url in data['urls'] if url.mirror.tier == tier]
data['version'] = 3
to_json = json.dumps(data, ensure_ascii=False, cls=MirrorStatusJSONEncoder)
response = HttpResponse(to_json, content_type='application/json')