Skip to content

Commit a91df60

Browse files
author
Steve Lamb
committed
Merge pull request #53 from azavea/topic/dont_localize_dates
Don't localize dates
2 parents 872e7bf + adb5034 commit a91df60

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

djqscsv/djqscsv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ def _validate_and_clean_filename(filename):
140140
def _sanitize_unicode_record(record):
141141

142142
def _sanitize_value(value):
143-
if isinstance(val, unicode):
143+
if isinstance(value, unicode):
144144
return value.encode("utf-8")
145+
elif isinstance(value, datetime.datetime):
146+
return value.isoformat().encode("utf-8")
145147
else:
146148
return localize(value)
147149

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='django-queryset-csv',
8-
version='0.2.8',
8+
version='0.2.9',
99
description='A simple python module for writing querysets to csv',
1010
long_description=open('README.rst').read(),
1111
author=author,

test_app/djqscsv_tests/tests/test_utilities.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime
2+
13
from django.test import TestCase
24
from django.core.exceptions import ValidationError
35

@@ -46,6 +48,14 @@ def test_sanitize(self):
4648
{'name': 'Tenar',
4749
'nickname': '\xef\xbb\xbfThe White Lady of Gont'})
4850

51+
def test_sanitize_date(self):
52+
record = {'name': 'Tenar',
53+
'created': datetime.datetime(1, 1, 1)}
54+
sanitized = djqscsv._sanitize_unicode_record(record)
55+
self.assertEqual(sanitized,
56+
{'name': 'Tenar',
57+
'created': '0001-01-01T00:00:00'})
58+
4959

5060
class AppendDatestampTests(TestCase):
5161

0 commit comments

Comments
 (0)