Ignore:
Timestamp:
7 May 2012, 10:15:21 (13 years ago)
Author:
uli
Message:

Add hash by default when exporting dates.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/utils
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py

    r8333 r8380  
    2323import grok
    2424import csv
     25import datetime
    2526import os
    2627import tempfile
     
    405406            # CSV writers like byte streams better than unicode
    406407            value = value.encode('utf-8')
     408        elif isinstance(value, datetime.datetime):
     409            value = str(value)
     410        elif isinstance(value, datetime.date):
     411            # Order is important here: check for date after datetime as
     412            # datetimes are also dates.
     413            #
     414            # Append hash '#' to dates to circumvent unwanted excel automatic
     415            value = str('%s#' % value)
    407416        elif value is None:
    408417            # None is not really representable in CSV files
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_batching.py

    r8228 r8380  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
     18import datetime
    1819import doctest
    1920import logging
     
    268269        result4 = exporter.mangle_value(u'string', 'foo')
    269270        result5 = exporter.mangle_value(None, 'foo')
     271        result6 = exporter.mangle_value(datetime.date(2012, 4, 1), 'foo')
     272        result7 = exporter.mangle_value(
     273            datetime.datetime(2012, 4, 1, 12, 1, 1), 'foo')
    270274        self.assertEqual(
    271275            (result1, result2, result3, result4, result5),
     
    273277        self.assertEqual(type(result3), type('string'))
    274278        self.assertEqual(type(result4), type('string'))
     279        # dates are formatted with trailing hash
     280        self.assertEqual(result6, '2012-04-01#')
     281        # datetimes are formatted as yyyy-mm-dd hh:mm:ss
     282        self.assertEqual(result7, '2012-04-01 12:01:01')
    275283        return
    276284
Note: See TracChangeset for help on using the changeset viewer.