Hi Oleg,

I'm just wondering if there is a reason why the TimeValidator class in Col.py 
does not also have the from_python method defined to be:

from_python = to_python

as is done for in the DateValidator class?

With this method defined in the DateValidator for example, one can set the 
date for a DateCol field using a string like "2010-01-31", without having to 
first instantiate a datetime.date() instance. The column validators chain 
would take care of converting the string to the correct type for the DateCol, 
depending on the column's dateFormat specification, of course.

But, the TimeValidator does not have the from_python method set like for the 
DateValidator, which means that one can not conveniently use string of the 
format "17:59:20" to set the value for a TimeCol(), and must first create and 
instance of datetime.time() in order to set the TimeCol() value.

Since SOTimeCol already have a timeFormat attribute which seems to be used in 
exactly the same way as the dateFormat attr for a DateCol, it seems that 
setting the from_python method on TimeValidator may just have been an 
oversight, or else there is another reason I am not aware of.

If it is an oversight, the small patch attached would allow strings to be used 
to set TimeCol values just as they are now conveniently usable for setting 
DateCol values.

IWBN if you can have a quick look and see if this can be added to future 
releases.



Cheers,
 Tom


Index: col.py
===================================================================
--- col.py	(revision 4100)
+++ col.py	(working copy)
@@ -1225,6 +1225,8 @@
             value = value.time()
         return value
 
+    from_python = to_python
+
 class SOTimeCol(SOCol):
     timeFormat = '%H:%M:%S'
 
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to