DateConverter validator can't parse str(datetime.date) objects
"Matthew Wilson" <[email protected]> Sat, 6 Sep 2008 19:36:31 -0400
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
I'm using the formencodel.validators.DateConverter class to convert
strings collected from an HTML web form into datetime.date objects.
On the first page load, I draw the form blank. Then on the second
page, I populate the form with the values passed in.
Here's the problem:
DateConverter().to_python(...) returns a datetime.date object. When I
convert datetime.date to a string, it renders itself like this into a
string that can't be parsed by the DateConverter.
This strikes me as really weird.
Here's some code that demonstrates my problem:
>>> dc = formencode.validators.DateConverter()
>>> dc.to_python('09-06-2008') # today
datetime.date(2008, 9, 6)
>>> today = dc.to_python('09-06-2008')
>>> today
datetime.date(2008, 9, 6)
>>> str(today)
'2008-09-06'
>>> dc.to_python(str(today))
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "/home/matt/virtualenvs/turbogears/lib/python2.5/site-packages/FormEncode-1.0.1-py2.5.egg/formencode/api.py",
line 381, in to_python
value = tp(value, state)
File "/home/matt/virtualenvs/turbogears/lib/python2.5/site-packages/FormEncode-1.0.1-py2.5.egg/formencode/validators.py",
line 1818, in _to_python
return self.convert_day(value, state)
File "/home/matt/virtualenvs/turbogears/lib/python2.5/site-packages/FormEncode-1.0.1-py2.5.egg/formencode/validators.py",
line 1828, in convert_day
value, state)
Invalid: Please enter the date in the form mm/dd/yyyy
See how I can't convert my converted stuff into a string and then feed
it back through?
Matt
--
Matthew Wilson
[email protected]
http://tplus1.com
216-470-6058
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/