quickinfo: show all images for a material

This commit is contained in:
2020-01-17 21:55:35 -08:00
parent bdce950581
commit d7159b6765
3 changed files with 35 additions and 12 deletions

View File

@ -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]

View File

@ -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)

View File

@ -9,18 +9,22 @@
<style>
html, body {
font-family: sans-serif;
height: 100%;
padding: 10px;
background-color: #535353;
}
#both {
width: 400px;
background-color: #fff;
box-shadow: 8px 8px 12px 0 rgba(0, 0, 0, 0.3);
position: relative;
margin: 0 auto;
width: -webkit-fit-content;
width: -moz-fit-content;
width: fit-content;
}
#image {
padding: 15px;
width: 250px;
display: inline-block;
}
#data {
border-top: 4px solid hsl(52, 100%, 50%);
@ -62,9 +66,13 @@
<body>
<div id="both">
<img class="logo" src="/static/img/keen_logo.svg" width="90">
{% if image %}
<div id="image">
<a href="{{ image }}"><img src="{{ image }}"/></a>
{% if images %}
<div id="images">
{% for image in images %}
<div id="image">
<a href="{{ image }}"><img src="{{ image }}"/></a>
</div>
{% endfor %}
</div>
{% else %}
<p class="notfound">Image not found</p>