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
1=== modified file 'NEWS'
2--- NEWS 2011-01-06 03:29:10 +0000
3+++ NEWS 2011-01-19 01:56:27 +0000
4@@ -11,7 +11,9 @@
5 - When retrieving and using an object with Store.get(), Storm will no
6 longer issue two queries when there is a live invalidated object
7 (bug #697513).
8-
9+ - When a datetime object is returned by the database driver,
10+ DateVariable failed to detect and convert it to a date() object
11+ (bug #391601).
12
13
14 0.18 (2010-10-25)
15
16=== modified file 'storm/variables.py'
17--- storm/variables.py 2010-06-01 08:12:07 +0000
18+++ storm/variables.py 2011-01-19 01:56:27 +0000
19@@ -436,6 +436,8 @@
20 if from_db:
21 if value is None:
22 return None
23+ if isinstance(value, datetime):
24+ return value.date()
25 if isinstance(value, date):
26 return value
27 if not isinstance(value, (str, unicode)):
28
29=== modified file 'tests/variables.py'
30--- tests/variables.py 2009-03-04 16:56:58 +0000
31+++ tests/variables.py 2011-01-19 01:56:27 +0000
32@@ -554,6 +554,7 @@
33 date_str = "1977-05-04"
34 date_uni = unicode(date_str)
35 date_obj = date(1977, 5, 4)
36+ datetime_obj = datetime(1977, 5, 4, 0, 0, 0)
37
38 variable = DateVariable()
39
40@@ -563,6 +564,8 @@
41 self.assertEquals(variable.get(), date_obj)
42 variable.set(date_obj, from_db=True)
43 self.assertEquals(variable.get(), date_obj)
44+ variable.set(datetime_obj, from_db=True)
45+ self.assertEquals(variable.get(), date_obj)
46
47 self.assertRaises(TypeError, variable.set, 0, from_db=True)
48 self.assertRaises(TypeError, variable.set, marker, from_db=True)

Subscribers

People subscribed via source and target branches

to status/vote changes: