Merge pull request #3994 from manassolanki/remove-markup

remove the markup while exporting the reports in csv format
This commit is contained in:
Rushabh Mehta 2017-08-24 18:41:51 +05:30 committed by GitHub
commit a6799f020f
2 changed files with 5 additions and 4 deletions

View file

@ -10,7 +10,7 @@ import frappe.permissions
import MySQLdb
from frappe.model.db_query import DatabaseQuery
from frappe import _
from six import text_type, string_types
from six import text_type, string_types, StringIO
@frappe.whitelist()
def get():
@ -146,13 +146,14 @@ def export_query():
# convert to csv
import csv
from six import StringIO
from frappe.utils.xlsxutils import handle_html
f = StringIO()
writer = csv.writer(f)
for r in data:
# encode only unicode type strings and not int, floats etc.
writer.writerow(map(lambda v: isinstance(v, text_type) and v.encode('utf-8') or v, r))
writer.writerow(map(lambda v: isinstance(v, string_types) and
handle_html(v.encode('utf-8')) or v, r))
f.seek(0)
frappe.response['result'] = text_type(f.read(), 'utf-8')

View file

@ -66,7 +66,7 @@ frappe.tools.to_csv = function(data) {
var res = [];
$.each(data, function(i, row) {
row = $.map(row, function(col) {
return typeof(col)==="string" ? ('"' + col.replace(/"/g, '""') + '"') : col;
return typeof(col)==="string" ? ('"' + $('<i>').html(col.replace(/"/g, '""')).text() + '"') : col;
});
res.push(row.join(","));
});