Only show POD image if so configured; use "image not found" fallback
also update a random docstring
This commit is contained in:
parent
892668f7f1
commit
c3487917ce
|
@ -580,6 +580,10 @@ class RattailConfig(object):
|
|||
"""
|
||||
Returns the title string to be used when displaying product key field,
|
||||
e.g. "UPC" or "Part No." etc.
|
||||
|
||||
:param key: The product key for which to return a label. This
|
||||
is optional; if not specified then :meth:`product_key()`
|
||||
will be called to determine the key.
|
||||
"""
|
||||
title = self.get('rattail', 'product.key_title')
|
||||
if title:
|
||||
|
|
|
@ -184,18 +184,30 @@ class ProductsHandler(GenericHandler):
|
|||
"""
|
||||
Return the preferred image URL for the given UPC or product.
|
||||
"""
|
||||
# we prefer the "image on file" if available
|
||||
if product and product.image:
|
||||
url = self.config.base_url()
|
||||
if url:
|
||||
return '{}/products/{}/image'.format(url, product.uuid)
|
||||
base_url = self.config.base_url()
|
||||
|
||||
# fallback to the POD image, if available
|
||||
# we prefer the "image on file" if available
|
||||
if base_url and product and product.image:
|
||||
return '{}/products/{}/image'.format(base_url, product.uuid)
|
||||
|
||||
# and if this product is a pack item, then we prefer the unit
|
||||
# item image as fallback, if available
|
||||
if base_url and product and product.is_pack_item():
|
||||
unit = product.unit
|
||||
if unit and unit.image:
|
||||
return '{}/products/{}/image'.format(base_url, unit.uuid)
|
||||
|
||||
# fallback to the POD image, if available and so configured
|
||||
if self.config.getbool('tailbone', 'products.show_pod_image',
|
||||
default=False):
|
||||
if product and not upc:
|
||||
upc = product.upc
|
||||
if upc:
|
||||
return self.get_pod_image_url(upc)
|
||||
|
||||
if base_url:
|
||||
return '{}/tailbone/img/product.png'.format(base_url)
|
||||
|
||||
def get_pod_image_url(self, upc, **kwargs):
|
||||
"""
|
||||
Return the POD image URL for the given UPC.
|
||||
|
|
Loading…
Reference in a new issue