Skip to content

Commit

Permalink
Use unicodecsv module to allow export of groups
Browse files Browse the repository at this point in the history
The groups CSV export was crashing due to unicode in group names. Use
the unicodecsv module to provide a unicode-safe CSV renderer.
  • Loading branch information
lenazun authored and nickstenning committed Feb 1, 2016
1 parent 9428f44 commit d231486
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion h/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Taken from:
# https://pyramid-cookbook.readthedocs.org/en/latest/templates/customrenderers.html
# with minor modifications
import csv
import unicodecsv as csv
from h._compat import StringIO


Expand Down
10 changes: 10 additions & 0 deletions h/test/renderers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ def test_render_simple_csv():
'rows': [[1, 2], [3, 4]]}

assert renderer(value, sys) == "One,Two\r\n1,2\r\n3,4\r\n"


def test_render_unicode_csv():
renderer = renderers.CSV({})
req = DummyRequest()
sys = {'request': req}
value = {'header': [u'ӓ', u'č'],
'rows': [[u'ñ', u'あ'], [u'ﺕ', u'Ӫ']]}

assert renderer(value, sys) == u"ӓ,č\r\nñ,あ\r\nﺕ,Ӫ\r\n".encode('utf-8')
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def run_tests(self):
'pyramid-jinja2>=2.3.3',
'raven>=5.8.0,<5.9.0',
'requests>=2.7.0',
'unicodecsv>=0.14.1,<0.15',
'ws4py>=0.3,<0.4',
'zope.sqlalchemy>=0.7.6,<0.8.0',

Expand Down

0 comments on commit d231486

Please sign in to comment.