On Wed, May 13, 2009 at 07:11:22PM +0000, Matthew Wilson wrote:
> Hi -- I wrote some code to add a TimedeltaCol type. I only tested it in
> postgresql.
Thank you!
> +def TimedeltaConverter(value, db):
> +
> + return """INTERVAL '%d days %d seconds'""" % \
> + (value.days, value.seconds)
> +
> +registerConverter(datetime.timedelta, TimedeltaConverter)
The syntax is only valid in Postgres, so it has to be protected:
def TimedeltaConverter(value, db):
if db == 'postgres':
return """INTERVAL '%d days %d seconds'""" % \
(value.days, value.seconds)
else:
raise ValueError('TimedeltaCol is only implemented for Postgres')
> +class TimedeltaValidator(validators.Validator):
> + def to_python(self, value, state):
> + return value
> +
> + def from_python(self, value, state):
> + return value
Why empty validator?
IWBN to have a test also.
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|