[FIX] image downloading, were not ported to werkzeug
bzr revid: xmo@openerp.com-20110906111157-hyzm016cyjcm0kfn
This commit is contained in:
parent
2b7beb7b10
commit
c96d60ca58
|
@ -971,17 +971,19 @@ class Binary(openerpweb.Controller):
|
||||||
|
|
||||||
@openerpweb.httprequest
|
@openerpweb.httprequest
|
||||||
def image(self, req, model, id, field, **kw):
|
def image(self, req, model, id, field, **kw):
|
||||||
req.httpresponse.headers['Content-Type'] = 'image/png'
|
|
||||||
Model = req.session.model(model)
|
Model = req.session.model(model)
|
||||||
context = req.session.eval_context(req.context)
|
context = req.session.eval_context(req.context)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not id:
|
if not id:
|
||||||
res = Model.default_get([field], context).get(field, '')
|
res = Model.default_get([field], context).get(field, '')
|
||||||
else:
|
else:
|
||||||
res = Model.read([int(id)], [field], context)[0].get(field, '')
|
res = Model.read([int(id)], [field], context)[0].get(field, '')
|
||||||
return base64.decodestring(res)
|
image_data = base64.decodestring(res)
|
||||||
except: # TODO: what's the exception here?
|
except: # TODO: what's the exception here?
|
||||||
return self.placeholder(req)
|
image_data = self.placeholder(req)
|
||||||
|
return req.make_response(image_data, [
|
||||||
|
('Content-Type', 'image/png'), ('Content-Length', len(image_data))])
|
||||||
def placeholder(self, req):
|
def placeholder(self, req):
|
||||||
return open(os.path.join(req.addons_path, 'web', 'static', 'src', 'img', 'placeholder.png'), 'rb').read()
|
return open(os.path.join(req.addons_path, 'web', 'static', 'src', 'img', 'placeholder.png'), 'rb').read()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue