@@ -79,17 +79,23 @@ def file_icon_context(file, detail, width, height):
79
79
context ['download_url' ] = file .url
80
80
if isinstance (file , BaseImage ):
81
81
thumbnailer = get_thumbnailer (file )
82
- if detail :
83
- width , height = 210 , ceil (210 / file .width * file .height )
84
- context ['sidebar_image_ratio' ] = file .width / 210
85
- opts = {'size' : (width , height ), 'upscale' : True }
82
+
83
+ # SVG files may contain multiple vector graphics, and width and height are not available for them. If file does
84
+ # not have width or height just ignore the thumbnail icon. Otherwise, continue with the standard procedure.
85
+ if file .width == 0.0 or file .height == 0.0 :
86
+ icon_url = staticfiles_storage .url ('filer/icons/file-unknown.svg' )
86
87
else :
87
- opts = {'size' : (width , height ), 'crop' : True }
88
- icon_url = thumbnailer .get_thumbnail (opts ).url
89
- context ['alt_text' ] = file .default_alt_text
90
- if mime_subtype != 'svg+xml' :
91
- opts ['size' ] = 2 * width , 2 * height
92
- context ['highres_url' ] = thumbnailer .get_thumbnail (opts ).url
88
+ if detail :
89
+ width , height = 210 , ceil (210 / file .width * file .height )
90
+ context ['sidebar_image_ratio' ] = file .width / 210
91
+ opts = {'size' : (width , height ), 'upscale' : True }
92
+ else :
93
+ opts = {'size' : (width , height ), 'crop' : True }
94
+ icon_url = thumbnailer .get_thumbnail (opts ).url
95
+ context ['alt_text' ] = file .default_alt_text
96
+ if mime_subtype != 'svg+xml' :
97
+ opts ['size' ] = 2 * width , 2 * height
98
+ context ['highres_url' ] = thumbnailer .get_thumbnail (opts ).url
93
99
elif mime_maintype in ['audio' , 'font' , 'video' ]:
94
100
icon_url = staticfiles_storage .url ('filer/icons/file-{}.svg' .format (mime_maintype ))
95
101
elif mime_maintype == 'application' and mime_subtype in ['zip' , 'pdf' ]:
0 commit comments