@http.route([
'/website/image',
- '/website/image/<model>-<id>-<field>',
- '/website/image/<model>-<id>-<field>-<int:max_width>x<int:max_height>'
+ '/website/image/<model>/<id>/<field>',
+ '/website/image/<model>/<id>/<field>/<int:max_width>x<int:max_height>'
], auth="public", website=True)
def website_image(self, model, id, field, max_width=None, max_height=None):
""" Fetches the requested field and ensures it does not go above
url = element.find('img').get('src')
url_object = urlparse.urlsplit(url)
- query = dict(urlparse.parse_qsl(url_object.query))
- if url_object.path == '/website/image':
- item = self.pool[query['model']].browse(
- cr, uid, int(query['id']), context=context)
- return item[query['field']]
+ if url_object.path.startswith('/website/image'):
+ # url might be /website/image/<model>/<id>[_<checksum>]/<field>[/<width>x<height>]
+ fragments = url_object.path.split('/')
+ query = dict(urlparse.parse_qsl(url_object.query))
+ model = query.get('model', fragments[3])
+ oid = query.get('id', fragments[4].split('_')[0])
+ field = query.get('field', fragments[5])
+ item = self.pool[model].browse(cr, uid, int(oid), context=context)
+ return item[field]
if self.local_url_re.match(url_object.path):
return self.load_local_url(url)
return response
data = record[field].decode('base64')
+ image = Image.open(cStringIO.StringIO(data))
+ response.mimetype = Image.MIME[image.format]
+
+ filename = '%s_%s.%s' % (model.replace('.', '_'), id, str(image.format).lower())
+ response.headers['Content-Disposition'] = 'inline; filename="%s"' % filename
if (not max_width) and (not max_height):
response.data = data
return response
- image = Image.open(cStringIO.StringIO(data))
- response.mimetype = Image.MIME[image.format]
-
w, h = image.size
max_w = int(max_width) if max_width else maxint
max_h = int(max_height) if max_height else maxint
"""Returns a local url that points to the image field of a given browse record."""
model = record._name
id = '%s_%s' % (record.id, hashlib.sha1(record.sudo().write_date).hexdigest()[0:7])
- size = '' if size is None else '-%s' % size
- return '/website/image/%s-%s-%s%s' % (model, id, field, size)
+ size = '' if size is None else '/%s' % size
+ return '/website/image/%s/%s/%s%s' % (model, id, field, size)
class website_menu(osv.osv):
if (product_id) {
var $img = $(this).closest('tr.js_product, .oe_website_sale').find('span[data-oe-model^="product."][data-oe-type="image"] img');
- $img.attr("src", "/website/image/product.product-" + product_id + "-image");
+ $img.attr("src", "/website/image/product.product/" + product_id + "/image");
$img.parent().attr('data-oe-model', 'product.product').attr('data-oe-id', product_id)
.data('oe-model', 'product.product').data('oe-id', product_id);
}