When source image of an {% image %} tag is missing, output a broken link rather than dying completely

pull/28/head
Matt Westcott 2014-02-10 16:55:14 +00:00
rodzic 9857ebdbde
commit 617184b319
1 zmienionych plików z 12 dodań i 2 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
from django import template
from wagtail.wagtailimages.models import Filter
from wagtail.wagtailimages.models import Filter, Rendition
register = template.Library()
@ -42,7 +42,17 @@ class ImageNode(template.Node):
if not image:
return ''
rendition = image.get_rendition(self.filter)
try:
rendition = image.get_rendition(self.filter)
except IOError:
# It's fairly routine for people to pull down remote databases to their
# local dev versions without retrieving the corresponding image files.
# In such a case, we would get an IOError at the point where we try to
# create the resized version of a non-existent image. Since this is a
# bit catastrophic for a missing image, we'll substitute a dummy
# Rendition object so that we just output a broken link instead.
rendition = Rendition(image=image, width=0, height=0)
rendition.file.name = 'not-found'
if self.output_var_name:
# return the rendition object in the given variable