catch SourceImageIOError when rendering image formats - fixes #801

This commit is contained in:
Matt Westcott 2014-11-13 16:11:30 +00:00 committed by Karl Hobley
parent fbf0d9002c
commit 6e232d74e1

View file

@ -1,6 +1,7 @@
from django.utils.html import escape
from wagtail.utils.apps import get_app_submodules
from wagtail.wagtailimages.models import SourceImageIOError
class Format(object):
@ -25,7 +26,15 @@ class Format(object):
)
def image_to_html(self, image, alt_text, extra_attributes=''):
rendition = image.get_rendition(self.filter_spec)
try:
rendition = image.get_rendition(self.filter_spec)
except SourceImageIOError:
# Image file is (probably) missing from /media/original_images - generate a dummy
# rendition so that we just output a broken image, rather than crashing out completely
# during rendering
Rendition = image.renditions.model # pick up any custom Image / Rendition classes that may be in use
rendition = Rendition(image=image, width=0, height=0)
rendition.file.name = 'not-found'
if self.classnames:
class_attr = 'class="%s" ' % escape(self.classnames)