Merge pull request #183 from odoo-dev/urlencodify

Improve handling of website image fields
This commit is contained in:
xmo-odoo 2014-05-23 15:13:13 +02:00
commit 14fb733ab2
2 changed files with 16 additions and 10 deletions

View File

@ -15,6 +15,7 @@ import urllib2
import urlparse
import re
import werkzeug.urls
import werkzeug.utils
from dateutil import parser
from lxml import etree, html
@ -265,16 +266,19 @@ class Image(orm.AbstractModel):
if options is None: options = {}
classes = ['img', 'img-responsive'] + options.get('class', '').split()
size_params = []
if options.has_key('max_width'):
size_params.append("max_width=%i" % options['max_width'])
if options.has_key('max_height'):
size_params.append("max_height=%i" % options['max_height'])
url_params = {
'model': record._model._name,
'field': field_name,
'id': record.id,
}
for options_key in ['max_width', 'max_height']:
if options.get(options_key):
url_params[options_key] = options[options_key]
return ir_qweb.HTMLSafe('<img class="%s" src="/website/image?model=%s&field=%s&id=%s&%s"/>' % (
return ir_qweb.HTMLSafe('<img class="%s" src="/website/image?%s"/>' % (
' '.join(itertools.imap(werkzeug.utils.escape, classes)),
record._model._name,
field_name, record.id, '&'.join(size_params)))
werkzeug.urls.url_encode(url_params)
))
local_url_re = re.compile(r'^/(?P<module>[^]]+)/static/(?P<rest>.+)$')
def from_html(self, cr, uid, model, column, element, context=None):

View File

@ -555,8 +555,10 @@ class website(osv.osv):
if record.get(presized):
response.data = data
return response
fit = int(max_width), int(max_height)
try:
fit = int(max_width), int(max_height)
except TypeError:
fit = (maxint, maxint)
w, h = image.size
max_w, max_h = fit