Add initial support for native product images

Definitely not perfect yet, but a start..
This commit is contained in:
Lance Edgar 2017-02-23 13:21:19 -06:00
parent 507f742edf
commit cf059baffa
2 changed files with 24 additions and 2 deletions

View file

@ -110,7 +110,11 @@
${self.render_main_fields(form)}
</div>
% if image_url:
% if image_path is not Undefined:
${h.image(image_url, "Product Image", id='product-image', path=image_path, use_pil=False)}
% else:
${h.image(image_url, "Product Image", id='product-image', width=150, height=150)}
% endif
% endif
</div>
</div>

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2016 Lance Edgar
# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
@ -29,6 +29,7 @@ from __future__ import unicode_literals, absolute_import
import os
import re
import six
import sqlalchemy as sa
from sqlalchemy import orm
@ -345,6 +346,19 @@ class ProductsView(MasterView):
'instance_title': self.get_instance_title(instance),
'form': form})
def image(self):
"""
View which renders the product's image as a response.
"""
product = self.get_instance()
if not product.image:
raise httpexceptions.HTTPNotFound()
# 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')
self.request.response.body = product.image.bytes
return self.request.response
def search(self):
"""
Locate a product(s) by UPC.
@ -562,6 +576,10 @@ class ProductsView(MasterView):
cls._defaults(config)
# product image
config.add_route('products.image', '/products/{uuid}/image')
config.add_view(cls, attr='image', route_name='products.image')
class ProductVersionView(VersionView):
"""