@@ -38,6 +38,9 @@ def get_size(self, width=None, height=None):
3838 if self .rel_image :
3939 width = self .rel_image .width
4040 height = self .rel_image .height
41+ else :
42+ width = 0
43+ height = 0
4144 else :
4245 # If no information is available on the image size whatsoever,
4346 # make it 640px wide and use PICTURE_RATIO
@@ -83,19 +86,26 @@ def img_srcset_data(self):
8386 return None
8487
8588 srcset = []
86- thumbnailer = get_thumbnailer (self .rel_image )
87- picture_options = self .get_size (self .width , self .height )
88- picture_width = picture_options ["size" ][0 ]
89- thumbnail_options = {"crop" : picture_options ["crop" ]}
90- breakpoints = getattr (
91- settings ,
92- "DJANGOCMS_PICTURE_RESPONSIVE_IMAGES_VIEWPORT_BREAKPOINTS" ,
93- [576 , 768 , 992 ],
94- )
9589
96- for size in filter (lambda x : x < picture_width , breakpoints ):
97- thumbnail_options ["size" ] = (size , size )
98- srcset .append ((int (size ), thumbnailer .get_thumbnail (thumbnail_options )))
90+ try :
91+ thumbnailer = get_thumbnailer (self .rel_image )
92+
93+ picture_options = self .get_size (self .width , self .height )
94+ picture_width = picture_options ["size" ][0 ]
95+ thumbnail_options = {"crop" : picture_options ["crop" ]}
96+ breakpoints = getattr (
97+ settings ,
98+ "DJANGOCMS_PICTURE_RESPONSIVE_IMAGES_VIEWPORT_BREAKPOINTS" ,
99+ [576 , 768 , 992 ],
100+ )
101+
102+ for size in filter (lambda x : x < picture_width , breakpoints ):
103+ thumbnail_options ["size" ] = (size , size )
104+ srcset .append ((int (size ), thumbnailer .get_thumbnail (thumbnail_options )))
105+ except ValueError :
106+ # get_thumbnailer() raises this if it can't establish a `relative_name`.
107+ # This may mean that the filer image has been deleted
108+ pass
99109
100110 return srcset
101111
@@ -127,8 +137,14 @@ def img_src(self):
127137 else (),
128138 }
129139
130- thumbnailer = get_thumbnailer (self .rel_image )
131- return thumbnailer .get_thumbnail (thumbnail_options ).url
140+ try :
141+ thumbnailer = get_thumbnailer (self .rel_image )
142+ url = thumbnailer .get_thumbnail (thumbnail_options ).url
143+ except ValueError :
144+ # get_thumbnailer() raises this if it can't establish a `relative_name`.
145+ # This may mean that the filer image has been deleted
146+ url = ''
147+ return url
132148
133149 def get_short_description (self ):
134150 if self .external_picture :
0 commit comments