Merge branch 'master' of https://github.com/sshwsfc/mongoengine into sshwsfc-dev
This commit is contained in:
commit
559fc46037
@ -8,7 +8,7 @@ import pymongo
|
|||||||
import pymongo.dbref
|
import pymongo.dbref
|
||||||
import pymongo.son
|
import pymongo.son
|
||||||
import pymongo.binary
|
import pymongo.binary
|
||||||
import datetime
|
import datetime, time
|
||||||
import decimal
|
import decimal
|
||||||
import gridfs
|
import gridfs
|
||||||
import warnings
|
import warnings
|
||||||
@ -149,6 +149,8 @@ class IntField(BaseField):
|
|||||||
if self.max_value is not None and value > self.max_value:
|
if self.max_value is not None and value > self.max_value:
|
||||||
raise ValidationError('Integer value is too large')
|
raise ValidationError('Integer value is too large')
|
||||||
|
|
||||||
|
def prepare_query_value(self, op, value):
|
||||||
|
return int(value)
|
||||||
|
|
||||||
class FloatField(BaseField):
|
class FloatField(BaseField):
|
||||||
"""An floating point number field.
|
"""An floating point number field.
|
||||||
@ -172,6 +174,9 @@ class FloatField(BaseField):
|
|||||||
if self.max_value is not None and value > self.max_value:
|
if self.max_value is not None and value > self.max_value:
|
||||||
raise ValidationError('Float value is too large')
|
raise ValidationError('Float value is too large')
|
||||||
|
|
||||||
|
def prepare_query_value(self, op, value):
|
||||||
|
return float(value)
|
||||||
|
|
||||||
class DecimalField(BaseField):
|
class DecimalField(BaseField):
|
||||||
"""A fixed-point decimal number field.
|
"""A fixed-point decimal number field.
|
||||||
|
|
||||||
@ -226,6 +231,40 @@ class DateTimeField(BaseField):
|
|||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
assert isinstance(value, datetime.datetime)
|
assert isinstance(value, datetime.datetime)
|
||||||
|
|
||||||
|
def prepare_query_value(self, op, value):
|
||||||
|
if value is None:
|
||||||
|
return value
|
||||||
|
if isinstance(value, datetime.datetime):
|
||||||
|
return value
|
||||||
|
if isinstance(value, datetime.date):
|
||||||
|
return datetime.datetime(value.year, value.month, value.day)
|
||||||
|
|
||||||
|
# Attempt to parse a datetime:
|
||||||
|
#value = smart_str(value)
|
||||||
|
# split usecs, because they are not recognized by strptime.
|
||||||
|
if '.' in value:
|
||||||
|
try:
|
||||||
|
value, usecs = value.split('.')
|
||||||
|
usecs = int(usecs)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
usecs = 0
|
||||||
|
kwargs = {'microsecond': usecs}
|
||||||
|
try: # Seconds are optional, so try converting seconds first.
|
||||||
|
return datetime.datetime(*time.strptime(value, '%Y-%m-%d %H:%M:%S')[:6],
|
||||||
|
**kwargs)
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
try: # Try without seconds.
|
||||||
|
return datetime.datetime(*time.strptime(value, '%Y-%m-%d %H:%M')[:5],
|
||||||
|
**kwargs)
|
||||||
|
except ValueError: # Try without hour/minutes/seconds.
|
||||||
|
try:
|
||||||
|
return datetime.datetime(*time.strptime(value, '%Y-%m-%d')[:3],
|
||||||
|
**kwargs)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
class EmbeddedDocumentField(BaseField):
|
class EmbeddedDocumentField(BaseField):
|
||||||
"""An embedded document field. Only valid values are subclasses of
|
"""An embedded document field. Only valid values are subclasses of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user