Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: python
python:
- "2.6"
- "2.7"
- 2.6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to update the exclude configuration block below to remove the quotes around "2.6" to get the Travis CI builds to pass.

- 2.7
- 3.5
env:
- DJANGO=1.5
- DJANGO=1.6
Expand All @@ -10,12 +11,22 @@ env:
- DJANGO=1.9
matrix:
exclude:
- python: "2.6"
- python: 2.6
env: DJANGO=1.6
- python: 2.6
env: DJANGO=1.7
- python: "2.6"
- python: 2.6
env: DJANGO=1.8
- python: "2.6"
- python: 2.6
env: DJANGO=1.9
- python: 3.5
env: DJANGO=1.5
- python: 3.5
env: DJANGO=1.6
- python: 3.5
env: DJANGO=1.7


install:
- pip install -q Django==$DJANGO
- pip install -r dev_requirements.txt
Expand Down
13 changes: 7 additions & 6 deletions djqscsv/djqscsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def generate_filename(queryset, append_datestamp=False):
Takes a queryset and returns a default
base filename based on the underlying model
"""
base_filename = slugify(unicode(queryset.model.__name__)) + '_export.csv'
base_filename = slugify(six.text_type(queryset.model.__name__)) \
+ '_export.csv'

if append_datestamp:
base_filename = _append_datestamp(base_filename)
Expand All @@ -167,17 +168,17 @@ def _validate_and_clean_filename(filename):
else:
filename = filename[:-4]

filename = slugify(unicode(filename)) + '.csv'
filename = slugify(six.text_type(filename)) + '.csv'
return filename


def _safe_utf8_stringify(value):
if isinstance(value, str):
if isinstance(value, six.string_types):
return value
elif isinstance(value, unicode):
elif isinstance(value, six.binary_type):
return value.encode('utf-8')
else:
return unicode(value).encode('utf-8')
return six.text_type(value).encode('utf-8')


def _sanitize_unicode_record(field_serializer_map, record):
Expand All @@ -188,7 +189,7 @@ def _serialize_value(value):
if isinstance(value, datetime.datetime):
return value.isoformat()
else:
return unicode(value)
return six.text_type(value)

obj = {}
for key, val in six.iteritems(record):
Expand Down
7 changes: 1 addition & 6 deletions test_app/djqscsv_tests/tests/test_csv_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@

from djqscsv_tests.util import create_people_and_get_queryset

from django.utils import six

if six.PY3:
from io import StringIO
else:
from StringIO import StringIO
from django.utils.six import StringIO


class CSVTestCase(TestCase):
Expand Down
14 changes: 7 additions & 7 deletions test_app/djqscsv_tests/tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ def test_sanitize(self):
'nickname': u'\ufeffThe White Lady of Gont'}
sanitized = djqscsv._sanitize_unicode_record({}, record)
self.assertEqual(sanitized,
{'name': 'Tenar',
'nickname': '\xef\xbb\xbfThe White Lady of Gont'})
{b'name': b'Tenar',
b'nickname': b'\xef\xbb\xbfThe White Lady of Gont'})

def test_sanitize_date(self):
record = {'name': 'Tenar',
'created': datetime.datetime(1, 1, 1)}
sanitized = djqscsv._sanitize_unicode_record({}, record)
self.assertEqual(sanitized,
{'name': 'Tenar',
'created': '0001-01-01T00:00:00'})
{b'name': b'Tenar',
b'created': b'0001-01-01T00:00:00'})

def test_sanitize_date_with_non_string_formatter(self):
"""
Expand All @@ -71,16 +71,16 @@ def test_sanitize_date_with_non_string_formatter(self):
record = {'name': 'Tenar'}
serializer = {'name': lambda d: len(d)}
sanitized = djqscsv._sanitize_unicode_record(serializer, record)
self.assertEqual(sanitized, {'name': '5'})
self.assertEqual(sanitized, {b'name': b'5'})

def test_sanitize_date_with_formatter(self):
record = {'name': 'Tenar',
'created': datetime.datetime(1973, 5, 13)}
serializer = {'created': lambda d: d.strftime('%Y-%m-%d')}
sanitized = djqscsv._sanitize_unicode_record(serializer, record)
self.assertEqual(sanitized,
{'name': 'Tenar',
'created': '1973-05-13'})
{b'name': b'Tenar',
b'created': b'1973-05-13'})

def test_sanitize_date_with_bad_formatter(self):
record = {'name': 'Tenar',
Expand Down