From: Oleg B. <ph...@ma...> - 2005-01-09 08:45:19
|
On Sat, Jan 08, 2005 at 05:27:05PM -0500, Barry Warsaw wrote: > Okay, here's what I've come up with to do conversions to/from Python > datetimes. > > class DateTimeValidator(validators.DateValidator): > def fromPython(self, value, state): > return value.strftime('%Y-%m-%d %H:%M:%S') > > def toPython(self, value, state): > stime = time.strptime(value, '%Y-%m-%d %H:%M:%S') > secs = time.mktime(stime) > return datetime.datetime.fromtimestamp(secs) Looks almost good. ("Almost" because your forgot about value=None that is mapped to SQL NULL; the format string should be parameterized.) I will test it, extend for mxDateTime, and apply. > I'm not sure if it's expected that validators.DateValidator.fromPython() > should always return a string or not It should return anything that toPython() groks. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |