[FIX] web: binary fields in one2many widgets

Don't retrieve the binary contents just to display the size, but pass context
with bin_size=True instead
Always pass filename in download link

Combination of patches from the bug report from Enrico Ganzaroli, Cedric Le
Brouster and Holger Brunn
Fixes #4899, lp:1167429
This commit is contained in:
Stefan Rijnhart 2014-03-21 09:05:04 +00:00 committed by Martin Trigaux
parent d1a19bcb7f
commit 33a65c2b8e
3 changed files with 10 additions and 4 deletions

View File

@ -753,7 +753,7 @@ instance.web.DataSetStatic = instance.web.DataSet.extend({
var offset = options.offset || 0,
limit = options.limit || false;
var end_pos = limit && limit !== -1 ? offset + limit : this.ids.length;
return this.read_ids(this.ids.slice(offset, end_pos), fields);
return this.read_ids(this.ids.slice(offset, end_pos), fields, options);
},
set_ids: function (ids) {
this.ids = ids;

View File

@ -4391,8 +4391,12 @@ instance.web.form.One2ManyViewManager = instance.web.ViewManager.extend({
});
instance.web.form.One2ManyDataSet = instance.web.BufferedDataSet.extend({
get_context: function() {
get_context: function(extra_context) {
this.context = this.o2m.build_context();
if(extra_context)
{
this.context.add(extra_context);
}
return this.context;
}
});

View File

@ -2305,7 +2305,7 @@ instance.web.list.Binary = instance.web.list.Column.extend({
* @private
*/
_format: function (row_data, options) {
var text = _t("Download");
var text = _t("Download"), filename=_t('Binary file');
var value = row_data[this.id].value;
if (!value) {
return options.value_if_empty || '';
@ -2323,11 +2323,13 @@ instance.web.list.Binary = instance.web.list.Column.extend({
if (this.filename && row_data[this.filename]) {
text = _.str.sprintf(_t("Download \"%s\""), instance.web.format_value(
row_data[this.filename].value, {type: 'char'}));
filename = row_data[this.filename].value;
}
return _.template('<a href="<%-href%>"><%-text%></a> (<%-size%>)', {
return _.template('<a download="<%-download%>" href="<%-href%>"><%-text%></a> (<%-size%>)', {
text: text,
href: download_url,
size: instance.web.binary_to_binsize(value),
download: filename,
});
}
});