[ADD] Add Cache-Control support in Binary Image and kanban view
authorFabien Meghazi <fme@openerp.com>
Tue, 19 Jun 2012 09:06:42 +0000 (11:06 +0200)
committerFabien Meghazi <fme@openerp.com>
Tue, 19 Jun 2012 09:06:42 +0000 (11:06 +0200)
bzr revid: fme@openerp.com-20120619090642-o397qwkzanof1b04

addons/web/controllers/main.py
addons/web_kanban/static/src/js/kanban.js

index 2966b34..3526883 100644 (file)
@@ -1358,6 +1358,11 @@ class Binary(openerpweb.Controller):
             image_data = self.placeholder(req)
         headers.append(('ETag', retag))
         headers.append(('Content-Length', len(image_data)))
+        try:
+            ncache = int(kw.get('cache'))
+            headers.append(('Cache-Control', 'no-cache' if ncache == 0 else 'max-age=%s' % (ncache)))
+        except:
+            pass
         return req.make_response(image_data, headers)
     def placeholder(self, req):
         addons_path = openerpweb.addons_manifest['web']['addons_path']
index 2b12346..879894e 100644 (file)
@@ -740,9 +740,13 @@ instance.web_kanban.KanbanRecord = instance.web.OldWidget.extend({
         var email_md5 = $.md5(email);
         return 'http://www.gravatar.com/avatar/' + email_md5 + '.png?s=' + size + '&d=' + default_;
     },
-    kanban_image: function(model, field, id) {
+    kanban_image: function(model, field, id, cache) {
         id = id || '';
         var 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.
+            url += '&cache=' + parseInt(cache, 10);
+        }
         return url;
     },
     kanban_text_ellipsis: function(s, size) {