Fix product image view for python3

This commit is contained in:
Lance Edgar 2022-12-26 10:33:12 -06:00
parent b653351f71
commit b985124bef

View file

@ -45,7 +45,6 @@ from rattail.time import localtime, make_utc
import colander
from deform import widget as dfwidget
from pyramid import httpexceptions
from webhelpers2.html import tags, HTML
from tailbone import forms, grids
@ -828,7 +827,7 @@ class ProductView(MasterView):
price = self.Session.query(model.ProductPrice).get(key)
if price:
return price.product
raise httpexceptions.HTTPNotFound()
raise self.notfound()
def configure_form(self, f):
super(ProductView, self).configure_form(f)
@ -1757,10 +1756,13 @@ class ProductView(MasterView):
"""
product = self.get_instance()
if not product.image:
raise httpexceptions.HTTPNotFound()
raise self.notfound()
# TODO: how to properly detect image type?
# self.request.response.content_type = six.binary_type('image/png')
self.request.response.content_type = six.binary_type('image/jpeg')
# content_type = 'image/png'
content_type = 'image/jpeg'
if not six.PY3:
content_type = six.binary_type(content_type)
self.request.response.content_type = content_type
self.request.response.body = product.image.bytes
return self.request.response