From 528c12774d59c9017de157d85373b8c43b29eede Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 9 Aug 2012 14:54:19 +0200 Subject: [PATCH 1/3] [IMP] kanban_image uses json for id and is now tolerant to m2o id's bzr revid: fme@openerp.com-20120809125419-j4l0063qyy6antqu --- addons/web/controllers/main.py | 8 +++----- addons/web_kanban/static/src/js/kanban.js | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 7e79fd9d2ea..c5a5cfec5b6 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1373,15 +1373,13 @@ class Binary(openerpweb.Controller): retag = hashed_session try: + id = simplejson.loads(id) + if type(id) is list: + id = id[0] # m2o if not id: res = Model.default_get([field], context).get(field) image_data = base64.b64decode(res) else: - try: - id = int(id) - except (ValueError): - # objects might use virtual ids as string - pass res = Model.read([id], [last_update, field], context)[0] retag = hashlib.md5(res.get(last_update)).hexdigest() image_data = base64.b64decode(res.get(field)) diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js index ef273ea9ea1..b4cffcba2d5 100644 --- a/addons/web_kanban/static/src/js/kanban.js +++ b/addons/web_kanban/static/src/js/kanban.js @@ -757,6 +757,7 @@ instance.web_kanban.KanbanRecord = instance.web.OldWidget.extend({ } else if (this.record[field] && ! this.record[field].value) { url = "/web/static/src/img/placeholder.png"; } else { + id = escape(JSON.stringify(id)); url = instance.connection.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + id; if (cache !== undefined) { // Set the cache duration in seconds. From 1a3bd4596143b27cd7679b30711846eac88c5bf9 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 9 Aug 2012 15:48:51 +0200 Subject: [PATCH 2/3] [FIX] Used json with binary/image controller bzr revid: fme@openerp.com-20120809134851-3yl6skfch2q1f7q0 --- addons/web/static/src/js/view_form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index b8acdfea4cd..4d06cb2d767 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -4616,8 +4616,9 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({ if (this.get('value') && ! /^\d+(\.\d*)? \w+$/.test(this.get('value'))) { url = 'data:image/png;base64,' + this.get('value'); } else if (this.get('value')) { + var id = escape(JSON.stringify(this.view.datarecord.id || null)); url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' + - this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name + '&t=' + (new Date().getTime()); + this.view.dataset.model +'&id=' + id + '&field=' + this.name + '&t=' + (new Date().getTime()); } else { url = "/web/static/src/img/placeholder.png"; } From 594862e93a97b98be7b71e0ab0801d8724d74082 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 9 Aug 2012 16:23:46 +0200 Subject: [PATCH 3/3] [IMP] binary/image should be backward compatible when id url parameter is empty bzr revid: fme@openerp.com-20120809142346-79xiq48qbgx7743i --- addons/web/controllers/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index c5a5cfec5b6..38553502fc7 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1373,7 +1373,7 @@ class Binary(openerpweb.Controller): retag = hashed_session try: - id = simplejson.loads(id) + id = None if not id else simplejson.loads(id) if type(id) is list: id = id[0] # m2o if not id: