[IMP] correctly handle filenames in list view binaries
authorXavier Morel <xmo@openerp.com>
Tue, 10 Jan 2012 15:50:20 +0000 (16:50 +0100)
committerXavier Morel <xmo@openerp.com>
Tue, 10 Jan 2012 15:50:20 +0000 (16:50 +0100)
bzr revid: xmo@openerp.com-20120110155020-ab02qb0ktlfxnwvb

addons/web/controllers/main.py
addons/web/static/src/js/formats.js

index c775927..b640587 100644 (file)
@@ -1217,7 +1217,7 @@ class Binary(openerpweb.Controller):
                 filename = res.get(filename_field, '') or filename
             return req.make_response(filecontent,
                 [('Content-Type', 'application/octet-stream'),
-                 ('Content-Disposition', 'attachment; filename=' +  filename)])
+                 ('Content-Disposition', 'attachment; filename="%s"' % filename)])
 
     @openerpweb.httprequest
     def upload(self, req, callback, ufile):
index 4076c19..819301f 100644 (file)
@@ -289,11 +289,18 @@ openerp.web.format_cell = function (row_data, column, options) {
         return _.str.sprintf('<input type="checkbox" %s disabled="disabled"/>',
                  row_data[column.id].value ? 'checked="checked"' : '');
     case "binary":
+        var text = _t("Download"),
+            download_url = _.str.sprintf('/web/binary/saveas?session_id=%s&model=%s&field=%s&id=%d', openerp.connection.session_id, options.model, column.id, options.id);
+        if (column.filename) {
+            download_url += '&filename_field=' + column.filename;
+            if (row_data[column.filename]) {
+                text = _.str.sprintf(_t("Download \"%s\""), openerp.web.format_value(
+                        row_data[column.filename].value, {type: 'char'}));
+            }
+        }
         return _.str.sprintf('<a href="%(href)s">%(text)s</a> (%(size)s)', {
-            text: _t("Download"),
-            href: _.str.sprintf('/web/binary/saveas?session_id=%s&model=%s&field=%s&id=%d',
-                    openerp.connection.session_id, options.model,
-                    column.id, options.id),
+            text: text,
+            href: download_url,
             size: row_data[column.id].value
         });
     }