0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 01:46:24 +01:00

Allow an extra path component on image serve view

Currently, we only allow the following format for the serve view:

    /images/<signature/<id>/<filter>/

This URL doesn't look nice as an image is expected to be a standalone file. This commit makes the following format possible:

    /images/<signature/<id>/<filter>/test.jpg
This commit is contained in:
Karl Hobley 2015-11-07 15:15:05 +00:00
parent ea758167db
commit 0fe1a1294a
2 changed files with 29 additions and 1 deletions

View File

@ -226,6 +226,34 @@ class TestFrontendServeView(TestCase):
self.assertTrue(response.streaming)
self.assertEqual(response['Content-Type'], 'image/png')
def test_get_with_extra_component(self):
"""
Test that a filename can be optionally added to the end of the URL.
"""
# Generate signature
signature = generate_signature(self.image.id, 'fill-800x600')
# Get the image
response = self.client.get(reverse('wagtailimages_serve', args=(signature, self.image.id, 'fill-800x600')) + 'test.png')
# Check response
self.assertEqual(response.status_code, 200)
self.assertTrue(response.streaming)
self.assertEqual(response['Content-Type'], 'image/png')
def test_get_with_too_many_extra_components(self):
"""
A filename can be appended to the end of the URL, but it must not contain a '/'
"""
# Generate signature
signature = generate_signature(self.image.id, 'fill-800x600')
# Get the image
response = self.client.get(reverse('wagtailimages_serve', args=(signature, self.image.id, 'fill-800x600')) + 'test/test.png')
# URL pattern should not match
self.assertEqual(response.status_code, 404)
def test_get_invalid_signature(self):
"""
Test that an invalid signature returns a 403 response

View File

@ -5,5 +5,5 @@ from django.conf.urls import url
from wagtail.wagtailimages.views.serve import serve
urlpatterns = [
url(r'^(.*)/(\d*)/(.*)/$', serve, name='wagtailimages_serve'),
url(r'^([^/]*)/(\d*)/([^/]*)/[^/]*$', serve, name='wagtailimages_serve'),
]