[ADD] Added support for ETag in Binary#image
[REM] Removed kanban hack using Date#getDate() in url bzr revid: fme@openerp.com-20120618154710-luw8bt50bjtdlj7t
This commit is contained in:
parent
623c6d20f2
commit
5436e4fea8
|
@ -1331,19 +1331,34 @@ class Binary(openerpweb.Controller):
|
||||||
|
|
||||||
@openerpweb.httprequest
|
@openerpweb.httprequest
|
||||||
def image(self, req, model, id, field, **kw):
|
def image(self, req, model, id, field, **kw):
|
||||||
|
last_update = '__last_update'
|
||||||
Model = req.session.model(model)
|
Model = req.session.model(model)
|
||||||
context = req.session.eval_context(req.context)
|
context = req.session.eval_context(req.context)
|
||||||
|
headers = [('Content-Type', 'image/png')]
|
||||||
|
etag = req.httprequest.headers.get('If-None-Match')
|
||||||
|
hashed_session = hashlib.md5(req.session_id).hexdigest()
|
||||||
|
if etag:
|
||||||
|
if not id and hashed_session == etag:
|
||||||
|
return werkzeug.wrappers.Response(status=304)
|
||||||
|
else:
|
||||||
|
date = Model.read([int(id)], [last_update], context)[0].get(last_update)
|
||||||
|
if hashlib.md5(date).hexdigest() == etag:
|
||||||
|
return werkzeug.wrappers.Response(status=304)
|
||||||
|
|
||||||
|
retag = hashed_session
|
||||||
try:
|
try:
|
||||||
if not id:
|
if not id:
|
||||||
res = Model.default_get([field], context).get(field)
|
res = Model.default_get([field], context).get(field)
|
||||||
|
image_data = base64.b64decode(res)
|
||||||
else:
|
else:
|
||||||
res = Model.read([int(id)], [field], context)[0].get(field)
|
res = Model.read([int(id)], [last_update, field], context)[0]
|
||||||
image_data = base64.b64decode(res)
|
retag = hashlib.md5(res.get(last_update)).hexdigest()
|
||||||
|
image_data = base64.b64decode(res.get(field))
|
||||||
except (TypeError, xmlrpclib.Fault):
|
except (TypeError, xmlrpclib.Fault):
|
||||||
image_data = self.placeholder(req)
|
image_data = self.placeholder(req)
|
||||||
return req.make_response(image_data, [
|
headers.append(('ETag', retag))
|
||||||
('Content-Type', 'image/png'), ('Content-Length', len(image_data))])
|
headers.append(('Content-Length', len(image_data)))
|
||||||
|
return req.make_response(image_data, headers)
|
||||||
def placeholder(self, req):
|
def placeholder(self, req):
|
||||||
addons_path = openerpweb.addons_manifest['web']['addons_path']
|
addons_path = openerpweb.addons_manifest['web']['addons_path']
|
||||||
return open(os.path.join(addons_path, 'web', 'static', 'src', 'img', 'placeholder.png'), 'rb').read()
|
return open(os.path.join(addons_path, 'web', 'static', 'src', 'img', 'placeholder.png'), 'rb').read()
|
||||||
|
|
|
@ -743,10 +743,6 @@ instance.web_kanban.KanbanRecord = instance.web.OldWidget.extend({
|
||||||
kanban_image: function(model, field, id) {
|
kanban_image: function(model, field, id) {
|
||||||
id = id || '';
|
id = id || '';
|
||||||
var url = instance.connection.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + id;
|
var url = instance.connection.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + id;
|
||||||
if (this.record.__last_update && this.record.__last_update.raw_value) {
|
|
||||||
var time = instance.web.str_to_datetime(this.record.__last_update.raw_value).getTime();
|
|
||||||
url += '&t=' + time;
|
|
||||||
}
|
|
||||||
return url;
|
return url;
|
||||||
},
|
},
|
||||||
kanban_text_ellipsis: function(s, size) {
|
kanban_text_ellipsis: function(s, size) {
|
||||||
|
|
Loading…
Reference in New Issue