Use locale format to export CSV from print button
issue8635 review252101002
This commit is contained in:
1 parent
ec8838b41a
commit
4fcf8c5c8f
2 files changed
+20
-15
No files matched your search
@@ -350,7 +350,8 @@ class Form(SignalEvent, TabContent):
|
||||
with open(fname, 'w') as fp:
|
||||
writer = csv.writer(fp, delimiter=delimiter)
|
||||
writer.writerow(fields)
|
||||
writer.writerows(data)
|
||||
for row in data:
|
||||
writer.writerow(WinExport.format_row(row))
|
||||
os.close(fileno)
|
||||
common.file_open(fname, 'csv')
|
||||
|
||||
|
||||
@@ -312,20 +312,8 @@ class WinExport(WinCSV):
|
||||
delimiter=self.get_delimiter())
|
||||
if self.add_field_names.get_active():
|
||||
writer.writerow(fields)
|
||||
for line in data:
|
||||
row = []
|
||||
for val in line:
|
||||
if locale_format:
|
||||
if isinstance(val, Number):
|
||||
val = locale.str(val)
|
||||
elif isinstance(val, datetime.datetime):
|
||||
val = val.strftime(common.date_format() + ' %X')
|
||||
elif isinstance(val, datetime.date):
|
||||
val = val.strftime(common.date_format())
|
||||
elif isinstance(val, bool):
|
||||
val = int(val)
|
||||
row.append(val)
|
||||
writer.writerow(row)
|
||||
for row in data:
|
||||
writer.writerow(self.format_row(row, locale_format))
|
||||
if popup:
|
||||
if len(data) == 1:
|
||||
common.message(_('%d record saved.') % len(data))
|
||||
@@ -337,6 +325,22 @@ class WinExport(WinCSV):
|
||||
% exception, _('Error'))
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def format_row(cls, line, locale_format=True):
|
||||
row = []
|
||||
for val in line:
|
||||
if locale_format:
|
||||
if isinstance(val, Number):
|
||||
val = locale.str(val)
|
||||
elif isinstance(val, datetime.datetime):
|
||||
val = val.strftime(common.date_format() + ' %X')
|
||||
elif isinstance(val, datetime.date):
|
||||
val = val.strftime(common.date_format())
|
||||
elif isinstance(val, bool):
|
||||
val = int(val)
|
||||
row.append(val)
|
||||
return row
|
||||
|
||||
def export_click(self, treeview, event):
|
||||
path_at_pos = treeview.get_path_at_pos(int(event.x), int(event.y))
|
||||
if not path_at_pos or event.button != 1:
|
||||
|
||||
Reference in new issue
Block a user