Add initial support for native product images
Definitely not perfect yet, but a start..
This commit is contained in:
parent
507f742edf
commit
cf059baffa
|
@ -110,7 +110,11 @@
|
||||||
${self.render_main_fields(form)}
|
${self.render_main_fields(form)}
|
||||||
</div>
|
</div>
|
||||||
% if image_url:
|
% if image_url:
|
||||||
|
% if image_path is not Undefined:
|
||||||
${h.image(image_url, "Product Image", id='product-image', path=image_path, use_pil=False)}
|
${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
|
% endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2016 Lance Edgar
|
# Copyright © 2010-2017 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -29,6 +29,7 @@ from __future__ import unicode_literals, absolute_import
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import six
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
|
@ -345,6 +346,19 @@ class ProductsView(MasterView):
|
||||||
'instance_title': self.get_instance_title(instance),
|
'instance_title': self.get_instance_title(instance),
|
||||||
'form': form})
|
'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):
|
def search(self):
|
||||||
"""
|
"""
|
||||||
Locate a product(s) by UPC.
|
Locate a product(s) by UPC.
|
||||||
|
@ -562,6 +576,10 @@ class ProductsView(MasterView):
|
||||||
|
|
||||||
cls._defaults(config)
|
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):
|
class ProductVersionView(VersionView):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue