Add POD image support to product view page.

This commit is contained in:
Lance Edgar 2014-04-13 17:54:22 -07:00
parent 087342b09c
commit 389bb5dcc6
3 changed files with 40 additions and 1 deletions

View file

@ -78,6 +78,9 @@ requires = [
'waitress', # 0.8.1
'WebHelpers', # 1.3
'zope.sqlalchemy', # 0.7
# This is used to obtain POD image dimensions.
'PIL', # 1.1.7
]

View file

@ -1,6 +1,27 @@
<%inherit file="/products/crud.mako" />
${parent.body()}
<%def name="head_tags()">
${parent.head_tags()}
<style type="text/css">
#product-image {
float: left;
margin-left: 250px;
margin-top: 40px;
}
</style>
</%def>
<div class="form-wrapper">
<ul class="context-menu">
${self.context_menu_items()}
</ul>
${form.render()|n}
% if image:
${h.image(image_url, u"Product Image", id='product-image', path=image_path, use_pil=True)}
% endif
</div>
<% product = form.fieldset.model %>

View file

@ -26,6 +26,8 @@
Product Views
"""
import os
from sqlalchemy import and_
from sqlalchemy.orm import joinedload, aliased
@ -48,6 +50,7 @@ from rattail.db.model import (
Brand, Vendor, Department, Subdepartment, LabelProfile)
from rattail.gpc import GPC
from rattail.db.api import get_product_by_upc
from rattail.pod import get_image_url, get_image_path
from ..db import Session
from ..forms import GPCFieldRenderer, BrandFieldRenderer, PriceFieldRenderer
@ -264,6 +267,18 @@ class ProductCrud(CrudView):
del fs.current_price
return fs
def template_kwargs(self, form):
kwargs = {'image': False}
product = form.fieldset.model
if product.upc:
kwargs['image_url'] = get_image_url(
self.request.rattail_config, product.upc)
kwargs['image_path'] = get_image_path(
self.request.rattail_config, product.upc)
if os.path.exists(kwargs['image_path']):
kwargs['image'] = True
return kwargs
def products_search(request):
"""