Merge branch 'quickinfo_multi_image'

This commit is contained in:
2020-01-18 23:14:28 -08:00
3 changed files with 36 additions and 13 deletions

View File

@ -53,26 +53,41 @@ class ProductImageFormat(Enum):
class ProductImage:
THUMB_DIR = os.path.join(settings.ASSET_DIR, 'products/thumbs')
THUMB_URL = '/images/products/thumbs'
THUMB_URL = '/export/products/thumbs'
# ordered by thumbnail preference
VIEW_TYPES = ['C', '3Q', '3QL', '3QR', '3QRL', 'P', 'PL', 'P2', 'P2L',
'F3Q', 'L', 'PLA', 'PPS', 'PPS_WORN', 'PLD', 'OS', 'OSL',
'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>