kopia lustrzana https://github.com/wagtail/wagtail
Update ImageRendition field to return Image alt text
* Update ImageRendtion to use default_alt_text property of Image * Update example in documentation * Add a test for ImageRenditionField * Resolves #5816pull/6015/head
rodzic
829a9bbf06
commit
52cb7ab77b
docs
advanced_topics/api/v2
releases
wagtail/images
|
@ -21,6 +21,7 @@ Changelog
|
|||
* Add Reddit to oEmbed provider list (Luke Hardwick)
|
||||
* Add ability to replace the default Wagtail logo in the userbar, via `branding_logo` block (Meteor0id)
|
||||
* Remove sticky footer on small devices, so that content is not blocked and more easily editable (Saeed Tahmasebi)
|
||||
* Add ``alt`` property to ``ImageRenditionField`` api representation (Liam Mullens)
|
||||
* Fix: Support IPv6 domain (Alex Gleason, Coen van der Kamp)
|
||||
* Fix: Ensure link to add a new user works when no users are visible in the users list (LB (Ben Johnston))
|
||||
* Fix: `AbstractEmailForm` saved submission fields are now aligned with the email content fields, `form.cleaned_data` will be used instead of `form.fields` (Haydn Greatnews)
|
||||
|
|
|
@ -458,6 +458,7 @@ Contributors
|
|||
* Rick van Hattem
|
||||
* Luke Hardwick
|
||||
* Saeed Tahmasebi
|
||||
* Liam Mullens
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -240,7 +240,8 @@ This would add the following to the JSON:
|
|||
"feed_image_thumbnail": {
|
||||
"url": "/media/images/a_test_image.fill-100x100.jpg",
|
||||
"width": 100,
|
||||
"height": 100
|
||||
"height": 100,
|
||||
"alt": "image alt text"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ Other features
|
|||
* Add Reddit to oEmbed provider list (Luke Hardwick)
|
||||
* Remove sticky footer on small devices, so that content is not blocked and more easily editable (Saeed Tahmasebi)
|
||||
* Add ability to replace the default Wagtail logo in the userbar, via ``branding_logo`` block (Meteor0id)
|
||||
* Add `alt` property to `ImageRenditionField` api representation (Liam Mullens)
|
||||
|
||||
|
||||
Bug fixes
|
||||
|
|
|
@ -14,7 +14,8 @@ class ImageRenditionField(Field):
|
|||
"thumbnail": {
|
||||
"url": "/media/images/myimage.max-165x165.jpg",
|
||||
"width": 165,
|
||||
"height": 100
|
||||
"height": 100,
|
||||
"alt": "Image alt text"
|
||||
}
|
||||
|
||||
If there is an error with the source image. The dict will only contain a single
|
||||
|
@ -36,6 +37,7 @@ class ImageRenditionField(Field):
|
|||
('url', thumbnail.url),
|
||||
('width', thumbnail.width),
|
||||
('height', thumbnail.height),
|
||||
('alt', thumbnail.alt),
|
||||
])
|
||||
except SourceImageIOError:
|
||||
return OrderedDict([
|
||||
|
|
|
@ -506,7 +506,7 @@ class AbstractRendition(models.Model):
|
|||
|
||||
@property
|
||||
def alt(self):
|
||||
return self.image.title
|
||||
return self.image.default_alt_text
|
||||
|
||||
@property
|
||||
def attrs(self):
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from wagtail.images.api.fields import ImageRenditionField
|
||||
|
||||
from .utils import Image, get_test_image_file
|
||||
|
||||
|
||||
class TestImageRenditionField(TestCase):
|
||||
def setUp(self):
|
||||
self.image = Image.objects.create(
|
||||
title="Test image",
|
||||
file=get_test_image_file(),
|
||||
)
|
||||
|
||||
def test_api_representation(self):
|
||||
rendition = self.image.get_rendition('width-400')
|
||||
representation = ImageRenditionField('width-400').to_representation(self.image)
|
||||
self.assertEqual(set(representation.keys()), {'url', 'width', 'height', 'alt'})
|
||||
self.assertEqual(representation['url'], rendition.url)
|
||||
self.assertEqual(representation['width'], rendition.width)
|
||||
self.assertEqual(representation['height'], rendition.height)
|
||||
self.assertEqual(representation['alt'], rendition.alt)
|
Ładowanie…
Reference in New Issue