From 94b9878c8da1c3a4af90869e6b758eaaa3c8ebec Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 5 Apr 2020 22:57:42 +1000 Subject: [PATCH 1/2] Bug fix for stock api - If a part had an empty image, the thumbnail was improperly encoded --- InvenTree/stock/api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 3c3e5acce6..53d4b15d13 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -340,12 +340,17 @@ class StockList(generics.ListCreateAPIView): img = item['part__image'] - # Use the thumbnail image instead - fn, ext = os.path.splitext(img) + if img: + # Use the thumbnail image instead + fn, ext = os.path.splitext(img) - thumb = "{fn}.thumbnail{ext}".format(fn=fn, ext=ext) + thumb = "{fn}.thumbnail{ext}".format(fn=fn, ext=ext) - item['part__thumbnail'] = os.path.join(settings.MEDIA_URL, thumb) + thumb = os.path.join(settings.MEDIA_URL, thumb) + else: + thumb = '' + + item['part__thumbnail'] = thumb del item['part__image'] From 791eb63f35dada65aff33714e50d0c08d7a5579b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 5 Apr 2020 22:59:45 +1000 Subject: [PATCH 2/2] Same fix for Part API --- InvenTree/part/api.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index e032c73eeb..9b73f68973 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -225,11 +225,17 @@ class PartList(generics.ListCreateAPIView): # Use the 'thumbnail' image here instead of the full-size image # Note: The full-size image is used when requesting the /api/part// endpoint - fn, ext = os.path.splitext(img) - thumb = "{fn}.thumbnail{ext}".format(fn=fn, ext=ext) + if img: + fn, ext = os.path.splitext(img) - item['thumbnail'] = os.path.join(settings.MEDIA_URL, thumb) + thumb = "{fn}.thumbnail{ext}".format(fn=fn, ext=ext) + + thumb = os.path.join(settings.MEDIA_URL, thumb) + else: + thumb = '' + + item['thumbnail'] = thumb del item['image']