Commit 7f783184 authored by Kedar Aitawdekar's avatar Kedar Aitawdekar 💻

Updated methods.cast_to_data_type() to handle for date and ObjectId

parent 57474e7c
......@@ -2085,7 +2085,10 @@ def cast_to_data_type(value, data_type):
# print "\n\t\tin method: ", value, " == ", data_type
if data_type != "list":
value = value.strip()
try:
value = value.strip()
except Exception as e:
pass
casted_value = value
if data_type == "unicode":
casted_value = unicode(value)
......@@ -2126,11 +2129,14 @@ def cast_to_data_type(value, data_type):
casted_value = [i.strip() for i in value if i]
# print "casted_value",casted_value
elif data_type == "datetime.datetime":
# "value" should be in following example format
# In [10]: datetime.strptime( "11/12/2014", "%d/%m/%Y")
# Out[10]: datetime(2014, 12, 11, 0, 0)
casted_value = datetime.strptime(value, "%d/%m/%Y")
elif (data_type == "datetime.datetime") or (str(data_type) == "<type 'datetime.datetime'>"):
try:
# "value" should be in following example format
# In [10]: datetime.strptime( "11/12/2014", "%d/%m/%Y")
# Out[10]: datetime(2014, 12, 11, 0, 0)
casted_value = datetime.strptime(value, "%d/%m/%Y")
except Exception as e:
casted_value = datetime.strptime(value, "%d/%m/%Y %H:%M:%S:%f")
return casted_value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment