summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2014-01-11 20:37:12 +0100
committerDan McGee <dan@archlinux.org>2014-01-11 20:37:12 +0100
commitfe37b46c50b60a8302e70ccef3ab34306fd8ea39 (patch)
tree9f713ff22724c2306a6f74af7fbca21cdbea8440
parent3827215fa3335f8da3c82d4d098eb402b6d29dbc (diff)
downloadarchweb-fe37b46c50b60a8302e70ccef3ab34306fd8ea39.tar.gz
archweb-fe37b46c50b60a8302e70ccef3ab34306fd8ea39.tar.xz
Add a 'last_modified' function for mirror status pages
We can use this on both the HTML and JSON views of this data to prevent recomputation for smart clients that respect the modified date header. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--mirrors/views.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/mirrors/views.py b/mirrors/views.py
index 3433616..5429cea 100644
--- a/mirrors/views.py
+++ b/mirrors/views.py
@@ -11,6 +11,7 @@ from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.timezone import now
from django.views.decorators.csrf import csrf_exempt
+from django.views.decorators.http import condition
from django_countries.countries import COUNTRIES
from .models import (Mirror, MirrorUrl, MirrorProtocol, MirrorLog,
@@ -220,6 +221,11 @@ def url_details(request, name, url_id):
return render(request, 'mirrors/url_details.html', context)
+def status_last_modified(request, *args, **kwargs):
+ return MirrorLog.objects.values_list('check_time', flat=True).latest()
+
+
+@condition(last_modified_func=status_last_modified)
def status(request, tier=None):
if tier is not None:
tier = int(tier)
@@ -297,6 +303,7 @@ class ExtendedMirrorStatusJSONEncoder(MirrorStatusJSONEncoder):
return super(ExtendedMirrorStatusJSONEncoder, self).default(obj)
+@condition(last_modified_func=status_last_modified)
def status_json(request, tier=None):
if tier is not None:
tier = int(tier)