[ckan-changes] commit/ckan: kindly: [model] 1344 fix to_dict to converts to isoformat for all datetimes

Bitbucket commits-noreply at bitbucket.org
Wed Sep 14 17:27:07 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/f08215845dab/
changeset:   f08215845dab
user:        kindly
date:        2011-09-14 19:26:27
summary:     [model] 1344 fix to_dict to converts to isoformat for all datetimes
affected #:  3 files (791 bytes)

--- a/ckan/lib/create_test_data.py	Wed Sep 14 15:17:30 2011 +0100
+++ b/ckan/lib/create_test_data.py	Wed Sep 14 18:26:27 2011 +0100
@@ -1,5 +1,6 @@
 import cli
 from collections import defaultdict
+import datetime
 
 class CreateTestData(cli.CkanCommand):
     '''Create test data in the database.
@@ -525,6 +526,13 @@
               'title':'Government Information Locator Service',
               'url':'',
               'tags':'registry  country-usa  government  federal  gov  workshop-20081101 penguin',
+              'resources':[{'url':'http://www.dcsf.gov.uk/rsgateway/DB/SFR/s000859/SFR17_2009_tables.xls',
+                          'format':'XLS',
+                          'last_modified': datetime.datetime(2005,10,01),
+                          'description':'December 2009 | http://www.statistics.gov.uk/hub/id/119-36345'},
+                          {'url':'http://www.dcsf.gov.uk/rsgateway/DB/SFR/s000860/SFR17_2009_key.doc',
+                          'format':'DOC',
+                          'description':'http://www.statistics.gov.uk/hub/id/119-34565'}],
               'groups':'ukgov test1 test2 penguin',
               'license':'gpl-3.0',
               'notes':u'''From <http://www.gpoaccess.gov/gils/about.html>


--- a/ckan/model/domain_object.py	Wed Sep 14 15:17:30 2011 +0100
+++ b/ckan/model/domain_object.py	Wed Sep 14 18:26:27 2011 +0100
@@ -91,6 +91,8 @@
             val = getattr(self, col.name)
             if isinstance(val, datetime.date):
                 val = str(val)
+            if isinstance(val, datetime.datetime):
+                val = val.isoformat()
             _dict[col.name] = val
         return _dict
 


--- a/ckan/model/resource.py	Wed Sep 14 15:17:30 2011 +0100
+++ b/ckan/model/resource.py	Wed Sep 14 18:26:27 2011 +0100
@@ -98,7 +98,10 @@
         if not core_columns_only:
             cols = ['id', 'resource_group_id'] + cols + ['position']
         for col in cols:
-            _dict[col] = getattr(self, col)
+            value = getattr(self, col)
+            if isinstance(value, datetime.datetime):
+                value = value.isoformat()
+            _dict[col] = value
         for k, v in self.extras.items() if self.extras else []:
             _dict[k] = v
         if self.resource_group and not core_columns_only:

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list