public inbox for [email protected]
help / color / mirror / Atom feedFix for csv download issue [RM2253] [RM2214] [pgadmin4]
2+ messages / 2 participants
[nested] [flat]
* Fix for csv download issue [RM2253] [RM2214] [pgadmin4]
@ 2017-05-08 09:00 Harshal Dhumal <[email protected]>
2017-05-08 09:21 ` Re: Fix for csv download issue [RM2253] [RM2214] [pgadmin4] Murtuza Zabuawala <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Harshal Dhumal @ 2017-05-08 09:00 UTC (permalink / raw)
To: pgadmin-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()
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Fix for csv download issue [RM2253] [RM2214] [pgadmin4]
2017-05-08 09:00 Fix for csv download issue [RM2253] [RM2214] [pgadmin4] Harshal Dhumal <[email protected]>
@ 2017-05-08 09:21 ` Murtuza Zabuawala <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Murtuza Zabuawala @ 2017-05-08 09:21 UTC (permalink / raw)
To: Harshal Dhumal <[email protected]>; +Cc: pgadmin-hackers
Please hold on on this patch, I am also working on same type of issue.
I think my patch would cover RM#2253 & RM#2360
--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Mon, May 8, 2017 at 2:30 PM, Harshal Dhumal <
[email protected]> wrote:
> 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
>
>
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2017-05-08 09:21 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-05-08 09:00 Fix for csv download issue [RM2253] [RM2214] [pgadmin4] Harshal Dhumal <[email protected]>
2017-05-08 09:21 ` Murtuza Zabuawala <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox