Merge lp:~sidnei/storm/datetime-in-datevariable into lp:storm

Proposed by Sidnei da Silva
Status: Merged
Approved by: Jamu Kakar
Approved revision: 387
Merged at revision: 386
Proposed branch: lp:~sidnei/storm/datetime-in-datevariable
Merge into: lp:storm
Diff against target: 48 lines (+8/-1)
3 files modified
NEWS (+3/-1)
storm/variables.py (+2/-0)
tests/variables.py (+3/-0)
To merge this branch: bzr merge lp:~sidnei/storm/datetime-in-datevariable
Reviewer Review Type Date Requested Status
Jamu Kakar (community) Approve
James Henstridge Approve
Review via email: mp+46727@code.launchpad.net

Description of the change

Converts datetime() object coming from db into a date() object.

To post a comment you must log in.
Revision history for this message
James Henstridge (jamesh) wrote :

Looks good. Don't forget to update the NEWS file though.

review: Approve
387. By Sidnei da Silva

- Add NEWS entry

Revision history for this message
Jamu Kakar (jkakar) wrote :

Nice work, +1!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2011-01-06 03:29:10 +0000
+++ NEWS 2011-01-19 01:56:27 +0000
@@ -11,7 +11,9 @@
11 - When retrieving and using an object with Store.get(), Storm will no11 - When retrieving and using an object with Store.get(), Storm will no
12 longer issue two queries when there is a live invalidated object12 longer issue two queries when there is a live invalidated object
13 (bug #697513).13 (bug #697513).
1414 - When a datetime object is returned by the database driver,
15 DateVariable failed to detect and convert it to a date() object
16 (bug #391601).
1517
1618
170.18 (2010-10-25)190.18 (2010-10-25)
1820
=== modified file 'storm/variables.py'
--- storm/variables.py 2010-06-01 08:12:07 +0000
+++ storm/variables.py 2011-01-19 01:56:27 +0000
@@ -436,6 +436,8 @@
436 if from_db:436 if from_db:
437 if value is None:437 if value is None:
438 return None438 return None
439 if isinstance(value, datetime):
440 return value.date()
439 if isinstance(value, date):441 if isinstance(value, date):
440 return value442 return value
441 if not isinstance(value, (str, unicode)):443 if not isinstance(value, (str, unicode)):
442444
=== modified file 'tests/variables.py'
--- tests/variables.py 2009-03-04 16:56:58 +0000
+++ tests/variables.py 2011-01-19 01:56:27 +0000
@@ -554,6 +554,7 @@
554 date_str = "1977-05-04"554 date_str = "1977-05-04"
555 date_uni = unicode(date_str)555 date_uni = unicode(date_str)
556 date_obj = date(1977, 5, 4)556 date_obj = date(1977, 5, 4)
557 datetime_obj = datetime(1977, 5, 4, 0, 0, 0)
557558
558 variable = DateVariable()559 variable = DateVariable()
559560
@@ -563,6 +564,8 @@
563 self.assertEquals(variable.get(), date_obj)564 self.assertEquals(variable.get(), date_obj)
564 variable.set(date_obj, from_db=True)565 variable.set(date_obj, from_db=True)
565 self.assertEquals(variable.get(), date_obj)566 self.assertEquals(variable.get(), date_obj)
567 variable.set(datetime_obj, from_db=True)
568 self.assertEquals(variable.get(), date_obj)
566569
567 self.assertRaises(TypeError, variable.set, 0, from_db=True)570 self.assertRaises(TypeError, variable.set, 0, from_db=True)
568 self.assertRaises(TypeError, variable.set, marker, from_db=True)571 self.assertRaises(TypeError, variable.set, marker, from_db=True)

Subscribers

People subscribed via source and target branches

to status/vote changes: