From d7159b676568e73d4970e5c1844a5504f6521e9f Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Fri, 17 Jan 2020 21:55:35 -0800 Subject: [PATCH] quickinfo: show all images for a material --- products/models.py | 27 +++++++++++++++++++++------ quickinfo/views.py | 2 +- templates/quickinfo/result.html | 18 +++++++++++++----- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/products/models.py b/products/models.py index 5656c59..2275fbd 100644 --- a/products/models.py +++ b/products/models.py @@ -60,19 +60,34 @@ class ProductImage: 'T', 'TL', 'PACK', 'F', 'B', 'INT', 'ALT_INT', 'FLR', 'FRONT', 'BACK'] + # @staticmethod + # def get_image_path(sap, image_format): + # for view in ProductImage.VIEW_TYPES: + # path = os.path.join(ProductImage.THUMB_DIR, + # '{}_{}-{}'.format(sap, view, image_format.value)) + # if os.path.isfile(path): + # return path + @staticmethod - def get_image_path(sap, image_format): + def get_all_image_paths(sap, image_format): + paths = [] for view in ProductImage.VIEW_TYPES: path = os.path.join(ProductImage.THUMB_DIR, '{}_{}-{}'.format(sap, view, image_format.value)) if os.path.isfile(path): - return path + paths.append(path) + return paths + + # @staticmethod + # def get_image_url(sap, image_format): + # path = ProductImage.get_image_path(sap, image_format) + # if path: + # return path.replace(ProductImage.THUMB_DIR, ProductImage.THUMB_URL) @staticmethod - def get_image_url(sap, image_format): - path = ProductImage.get_image_path(sap, image_format) - if path: - return path.replace(ProductImage.THUMB_DIR, ProductImage.THUMB_URL) + def get_all_image_urls(sap, image_format): + paths = ProductImage.get_all_image_paths(sap, image_format) + return [p.replace(ProductImage.THUMB_DIR, ProductImage.THUMB_URL) for p in paths] diff --git a/quickinfo/views.py b/quickinfo/views.py index 75a0c9e..6f53c67 100644 --- a/quickinfo/views.py +++ b/quickinfo/views.py @@ -24,7 +24,7 @@ def result(request): except ObjectDoesNotExist: context['prod'] = None - context['image'] = ProductImage.get_image_url(id, ProductImageFormat.MED_JPG) + context['images'] = ProductImage.get_all_image_urls(id, ProductImageFormat.MED_JPG) return render(request, 'quickinfo/result.html', context) diff --git a/templates/quickinfo/result.html b/templates/quickinfo/result.html index 37f599c..1223871 100644 --- a/templates/quickinfo/result.html +++ b/templates/quickinfo/result.html @@ -9,18 +9,22 @@