mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 08:43:10 +00:00
Addition of attrs property to image template tag
This commit is contained in:
parent
9d8e16a73a
commit
cf3d6a4e66
2 changed files with 18 additions and 0 deletions
|
|
@ -225,6 +225,12 @@ class AbstractRendition(models.Model):
|
|||
def url(self):
|
||||
return self.file.url
|
||||
|
||||
@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))
|
||||
)
|
||||
|
||||
def img_tag(self):
|
||||
return mark_safe(
|
||||
'<img src="%s" width="%d" height="%d" alt="%s">' % (escape(self.url), self.width, self.height, escape(self.image.title))
|
||||
|
|
|
|||
|
|
@ -183,6 +183,18 @@ class TestImageTag(TestCase):
|
|||
self.assertTrue('height="300"' in result)
|
||||
self.assertTrue('alt="Test image"' in result)
|
||||
|
||||
def render_image_tag_as(self, image, filter_spec):
|
||||
temp = template.Template('{% load image_tags %}{% image image_obj ' + filter_spec + ' as test_img %}<img {{ test_img.attrs }} />')
|
||||
context = template.Context({'image_obj': image})
|
||||
return temp.render(context)
|
||||
|
||||
def test_image_tag_attrs(self):
|
||||
result = self.render_image_tag_as(self.image, 'width-400')
|
||||
|
||||
# Check that all the required HTML attributes are set
|
||||
self.assertTrue('width="400"' in result)
|
||||
self.assertTrue('height="300"' in result)
|
||||
self.assertTrue('alt="Test image"' in result)
|
||||
|
||||
## ===== ADMIN VIEWS =====
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue