kopia lustrzana https://github.com/wagtail/wagtail
Use a local URL for image previews
rodzic
b1c29ac848
commit
f60216d783
|
@ -47,7 +47,7 @@ $(function() {
|
||||||
$.getJSON(generatorUrl.replace('__filterspec__', filterSpec))
|
$.getJSON(generatorUrl.replace('__filterspec__', filterSpec))
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
$result.val(data['url']);
|
$result.val(data['url']);
|
||||||
$preview.attr('src', data['url']);
|
$preview.attr('src', data['local_url']);
|
||||||
$loadingMask.removeClass('loading');
|
$loadingMask.removeClass('loading');
|
||||||
})
|
})
|
||||||
.fail(function(data) {
|
.fail(function(data) {
|
||||||
|
|
|
@ -831,7 +831,7 @@ class TestGenerateURLView(TestCase, WagtailTestUtils):
|
||||||
# Check JSON
|
# Check JSON
|
||||||
content_json = json.loads(response.content.decode())
|
content_json = json.loads(response.content.decode())
|
||||||
|
|
||||||
self.assertEqual(list(content_json.keys()), ['url'])
|
self.assertEqual(set(content_json.keys()), set(['url', 'local_url']))
|
||||||
|
|
||||||
expected_url = 'http://localhost/images/%(signature)s/%(image_id)d/fill-800x600/' % {
|
expected_url = 'http://localhost/images/%(signature)s/%(image_id)d/fill-800x600/' % {
|
||||||
'signature': urlquote(generate_signature(self.image.id, 'fill-800x600').decode()),
|
'signature': urlquote(generate_signature(self.image.id, 'fill-800x600').decode()),
|
||||||
|
@ -839,6 +839,12 @@ class TestGenerateURLView(TestCase, WagtailTestUtils):
|
||||||
}
|
}
|
||||||
self.assertEqual(content_json['url'], expected_url)
|
self.assertEqual(content_json['url'], expected_url)
|
||||||
|
|
||||||
|
expected_local_url = '/images/%(signature)s/%(image_id)d/fill-800x600/' % {
|
||||||
|
'signature': urlquote(generate_signature(self.image.id, 'fill-800x600').decode()),
|
||||||
|
'image_id': self.image.id,
|
||||||
|
}
|
||||||
|
self.assertEqual(content_json['local_url'], expected_local_url)
|
||||||
|
|
||||||
def test_get_bad_permissions(self):
|
def test_get_bad_permissions(self):
|
||||||
"""
|
"""
|
||||||
This tests that the view gives a 403 if a user without correct permissions attemts to access it
|
This tests that the view gives a 403 if a user without correct permissions attemts to access it
|
||||||
|
|
|
@ -168,11 +168,13 @@ def generate_url(request, image_id, filter_spec):
|
||||||
signature = generate_signature(image_id, filter_spec)
|
signature = generate_signature(image_id, filter_spec)
|
||||||
url = reverse('wagtailimages_serve', args=(signature, image_id, filter_spec))
|
url = reverse('wagtailimages_serve', args=(signature, image_id, filter_spec))
|
||||||
|
|
||||||
# Add default sites root URL to the beginning
|
# Get site root url
|
||||||
site_root_url = Site.objects.get(is_default_site=True).root_url
|
try:
|
||||||
url = site_root_url + url
|
site_root_url = Site.objects.get(is_default_site=True).root_url
|
||||||
|
except Site.DoesNotExist:
|
||||||
|
site_root_url = Site.objects.first().root_url
|
||||||
|
|
||||||
return json_response({'url': url}, status=200)
|
return json_response({'url': site_root_url + url, 'local_url': url}, status=200)
|
||||||
|
|
||||||
|
|
||||||
@permission_required('wagtailadmin.access_admin') # more specific permission tests are applied within the view
|
@permission_required('wagtailadmin.access_admin') # more specific permission tests are applied within the view
|
||||||
|
|
Ładowanie…
Reference in New Issue