mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-18 14:00:59 +00:00
Add 'alt' property to image renditions - fixes #1517
This commit is contained in:
parent
e08e35d470
commit
4043dee92d
2 changed files with 9 additions and 2 deletions
|
|
@ -439,10 +439,14 @@ class AbstractRendition(models.Model):
|
|||
def url(self):
|
||||
return self.file.url
|
||||
|
||||
@property
|
||||
def alt(self):
|
||||
return self.image.title
|
||||
|
||||
@property
|
||||
def attrs(self):
|
||||
return mark_safe(
|
||||
'src="%s" width="%d" height="%d" alt="%s"' % (escape(self.url), self.width, self.height, escape(self.image.title))
|
||||
'src="%s" width="%d" height="%d" alt="%s"' % (escape(self.url), self.width, self.height, escape(self.alt))
|
||||
)
|
||||
|
||||
def img_tag(self, extra_attributes=None):
|
||||
|
|
|
|||
|
|
@ -190,7 +190,6 @@ class TestRenditions(TestCase):
|
|||
self.assertEqual(rendition.width, 100)
|
||||
self.assertEqual(rendition.height, 75)
|
||||
|
||||
|
||||
def test_resize_to_min(self):
|
||||
rendition = self.image.get_rendition('min-120x120')
|
||||
|
||||
|
|
@ -213,6 +212,10 @@ class TestRenditions(TestCase):
|
|||
# Check that they are the same object
|
||||
self.assertEqual(first_rendition, second_rendition)
|
||||
|
||||
def test_alt_attribute(self):
|
||||
rendition = self.image.get_rendition('width-400')
|
||||
self.assertEqual(rendition.alt, "Test image")
|
||||
|
||||
|
||||
class TestUsageCount(TestCase):
|
||||
fixtures = ['test.json']
|
||||
|
|
|
|||
Loading…
Reference in a new issue