public inbox for [email protected]
help / color / mirror / Atom feedFrom: Harshal Dhumal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: Fix for csv download issue [RM2253] [RM2214] [pgadmin4]
Date: Mon, 8 May 2017 14:30:55 +0530
Message-ID: <CAFiP3vwLNaSgocx2YssRgcEBDLgxXQCpb4M+MD6xybcKxH5K7Q@mail.gmail.com> (raw)
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgadmin-hackers>
Hi,
Pls find attached patch for csv download issue when data contains non ASCII
characters. And also when table name contains non ASCII characters
--
*Harshal Dhumal*
*Sr. Software Engineer*
EnterpriseDB India: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers
Attachments:
[text/x-patch] RM2253_RM2314.patch (1.9K, 3-RM2253_RM2314.patch)
download | inline diff:
diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py
index d114988..cdd790e 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -12,6 +12,7 @@ import simplejson as json
import os
import pickle
import random
+import time
from flask import Response, url_for, render_template, session, request
from flask_babel import gettext
@@ -1372,9 +1373,12 @@ def start_query_download_tool(trans_id):
r = Response(gen(), mimetype='text/csv')
if 'filename' in data and data['filename'] != "":
- filename = data['filename']
+ # Response headers only support latin-1 compatible strings.
+ try:
+ filename = data['filename'].encode('latin-1', 'strict')
+ except UnicodeEncodeError:
+ filename = str(int(time.time())) + ".csv"
else:
- import time
filename = str(int(time.time())) + ".csv"
r.headers["Content-Disposition"] = "attachment;filename={0}".format(filename)
diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py
index e474817..ff74eb7 100644
--- a/web/pgadmin/utils/driver/psycopg2/__init__.py
+++ b/web/pgadmin/utils/driver/psycopg2/__init__.py
@@ -648,7 +648,10 @@ WHERE
res_io, fieldnames=header, delimiter=str(','), quoting=csv.QUOTE_NONNUMERIC
)
csv_writer.writeheader()
- csv_writer.writerows(results)
+ # convert unicode records to utf-8 as csv writer do not support
+ # writing unicode data
+ csv_writer.writerows([{k: v.encode('utf-8') for k, v in row.items()}
+ for row in results])
yield res_io.getvalue()
view thread (2+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: Fix for csv download issue [RM2253] [RM2214] [pgadmin4]
In-Reply-To: <CAFiP3vwLNaSgocx2YssRgcEBDLgxXQCpb4M+MD6xybcKxH5K7Q@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox