Add 'alt' property to image renditions - fixes #1517

This commit is contained in:
Matt Westcott 2015-10-26 21:44:19 +00:00 committed by Karl Hobley
parent e08e35d470
commit 4043dee92d
2 changed files with 9 additions and 2 deletions

View file

@ -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):

View file

@ -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']