+8
-4
@@ -2149,7 +2149,7 @@
|
||||
}, this.session);
|
||||
}
|
||||
prm.then(data => {
|
||||
this.export_csv(data, paths).then(() => {
|
||||
this.export_csv(data, paths, header).then(() => {
|
||||
this.destroy();
|
||||
});
|
||||
});
|
||||
@@ -2157,7 +2157,7 @@
|
||||
this.destroy();
|
||||
}
|
||||
},
|
||||
export_csv: function(data, paths) {
|
||||
export_csv: function(data, paths, header=false) {
|
||||
var locale_format = this.el_csv_locale.prop('checked');
|
||||
var unparse_obj = {};
|
||||
unparse_obj.data = data.map(function(row, i) {
|
||||
@@ -2175,9 +2175,13 @@
|
||||
}
|
||||
Sao.common.download_file(
|
||||
csv, this.name + '.csv', {type: 'text/csv;charset=utf-8'});
|
||||
var size = data.length;
|
||||
if (header) {
|
||||
size -= 1;
|
||||
}
|
||||
return Sao.common.message.run(
|
||||
Sao.i18n.ngettext('%1 record saved', '%1 records saved',
|
||||
data.length));
|
||||
Sao.i18n.ngettext(
|
||||
"%1 record saved", "%1 records saved", size));
|
||||
},
|
||||
set_url: function() {
|
||||
var path = [this.session.database, 'data', this.screen.model_name];
|
||||
|
||||
@@ -371,18 +371,19 @@ class WinExport(WinCSV):
|
||||
fname = common.file_selection(_('Save As...'),
|
||||
action=Gtk.FileChooserAction.SAVE)
|
||||
if fname:
|
||||
self.export_csv(fname, data, paths)
|
||||
self.export_csv(fname, data, paths, header=header)
|
||||
else:
|
||||
fileno, fname = tempfile.mkstemp(
|
||||
'.csv', common.slugify(self.name) + '_')
|
||||
if self.export_csv(fname, data, paths, popup=False):
|
||||
if self.export_csv(
|
||||
fname, data, paths, popup=False, header=header):
|
||||
os.close(fileno)
|
||||
common.file_open(fname, 'csv')
|
||||
else:
|
||||
os.close(fileno)
|
||||
self.destroy()
|
||||
|
||||
def export_csv(self, fname, data, paths, popup=True):
|
||||
def export_csv(self, fname, data, paths, popup=True, header=False):
|
||||
encoding = self.csv_enc.get_active_text() or 'utf_8_sig'
|
||||
locale_format = self.csv_locale.get_active()
|
||||
|
||||
@@ -397,10 +398,13 @@ class WinExport(WinCSV):
|
||||
writer.writerow(self.format_row(
|
||||
row, indent=indent, locale_format=locale_format))
|
||||
if popup:
|
||||
if len(data) == 1:
|
||||
common.message(_('%d record saved.') % len(data))
|
||||
size = len(data)
|
||||
if header:
|
||||
size -= 1
|
||||
if size <= 1:
|
||||
common.message(_('%d record saved.') % size)
|
||||
else:
|
||||
common.message(_('%d records saved.') % len(data))
|
||||
common.message(_('%d records saved.') % size)
|
||||
return True
|
||||
except (IOError, UnicodeEncodeError, csv.Error) as exception:
|
||||
common.warning(str(exception), _('Export failed'))
|
||||
|
||||
Reference in New Issue
Block a user