From fe37b46c50b60a8302e70ccef3ab34306fd8ea39 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 11 Jan 2014 13:37:12 -0600 Subject: 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 --- mirrors/views.py | 7 +++++++ 1 file changed, 7 insertions(+) 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) -- cgit v1.2.3-24-g4f1b