diff --git a/wagtail/tests/settings.py b/wagtail/tests/settings.py index 4e7eaca6cb..1b4cb8d772 100644 --- a/wagtail/tests/settings.py +++ b/wagtail/tests/settings.py @@ -7,6 +7,7 @@ from django.conf import global_settings WAGTAIL_ROOT = os.path.dirname(__file__) STATIC_ROOT = os.path.join(WAGTAIL_ROOT, 'test-static') MEDIA_ROOT = os.path.join(WAGTAIL_ROOT, 'test-media') +MEDIA_URL = '/media/' DATABASES = { diff --git a/wagtail/wagtailimages/tests/tests.py b/wagtail/wagtailimages/tests/tests.py index 8dca205970..652f2c703e 100644 --- a/wagtail/wagtailimages/tests/tests.py +++ b/wagtail/wagtailimages/tests/tests.py @@ -140,13 +140,7 @@ class TestFrontendServeView(TestCase): response = self.client.get(reverse('wagtailimages_serve', args=(signature, self.image.id, 'fill-800x600'))) # Check response - self.assertEqual(response.status_code, 200) - self.assertEqual(response['Content-Type'], 'image/jpeg') - - # Make sure the cache headers are set to expire after at least one month - self.assertIn('Cache-Control', response) - self.assertEqual(response['Cache-Control'].split('=')[0], 'max-age') - self.assertTrue(int(response['Cache-Control'].split('=')[1]) > datetime.timedelta(days=30).seconds) + self.assertRedirects(response, self.image.renditions.first().url, status_code=301, target_status_code=404) def test_get_invalid_signature(self): """ diff --git a/wagtail/wagtailimages/views/frontend.py b/wagtail/wagtailimages/views/frontend.py index 0ad2534d36..7c792a1373 100644 --- a/wagtail/wagtailimages/views/frontend.py +++ b/wagtail/wagtailimages/views/frontend.py @@ -1,13 +1,11 @@ -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, redirect from django.http import HttpResponse from django.core.exceptions import PermissionDenied -from django.views.decorators.cache import cache_control from wagtail.wagtailimages.models import get_image_model, Filter from wagtail.wagtailimages.utils import verify_signature -@cache_control(max_age=60*60*24*60) # Cache for 60 days def serve(request, signature, image_id, filter_spec): image = get_object_or_404(get_image_model(), id=image_id) @@ -15,6 +13,7 @@ def serve(request, signature, image_id, filter_spec): raise PermissionDenied try: - return Filter(spec=filter_spec).process_image(image.file.file, HttpResponse(content_type='image/jpeg'), focal_point=image.get_focal_point()) + rendition = image.get_rendition(filter_spec) + return redirect(rendition.url, permanent=True) except Filter.InvalidFilterSpecError: return HttpResponse("Invalid filter spec: " + filter_spec, content_type='text/plain', status=400)