mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1647 from SchrodingersGat/thumbnail-error-catch
BuildItemSerializer: Handle errors when thumbnail is not found
This commit is contained in:
commit
120c371a11
@ -1289,10 +1289,23 @@ class BuildItem(models.Model):
|
||||
Return qualified URL for part thumbnail image
|
||||
"""
|
||||
|
||||
thumb_url = None
|
||||
|
||||
if self.stock_item and self.stock_item.part:
|
||||
return InvenTree.helpers.getMediaUrl(self.stock_item.part.image.thumbnail.url)
|
||||
elif self.bom_item and self.stock_item.sub_part:
|
||||
return InvenTree.helpers.getMediaUrl(self.bom_item.sub_part.image.thumbnail.url)
|
||||
try:
|
||||
# Try to extract the thumbnail
|
||||
thumb_url = self.stock_item.part.image.thumbnail.url
|
||||
except:
|
||||
pass
|
||||
|
||||
if thumb_url is None and self.bom_item and self.stock_item.sub_part:
|
||||
try:
|
||||
thumb_url = self.bom_item.sub_part.image.thumbnail.url
|
||||
except:
|
||||
pass
|
||||
|
||||
if thumb_url is not None:
|
||||
return InvenTree.helpers.getMediaUrl(thumb_url)
|
||||
else:
|
||||
return InvenTree.helpers.getBlankThumbnail()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user