Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions motorengine/fields/binary_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,27 @@ def __init__(self, max_bytes=None, *args, **kwargs):
self.max_bytes = max_bytes

def to_son(self, value):
if value is None:
return None

if not isinstance(value, (six.binary_type, )):
return six.b(value)

return value

def from_son(self, value):
if value is None:
return None

if not isinstance(value, (six.binary_type, )):
return six.b(value)

return value

def validate(self, value):
if value is None:
return True

if not isinstance(value, (six.binary_type, )):
return False

Expand Down
9 changes: 9 additions & 0 deletions motorengine/fields/decimal_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,24 @@ def __init__(self, min_value=None, max_value=None, precision=2, rounding=decimal
self.rounding = rounding

def to_son(self, value):
if value is None:
return None

value = decimal.Decimal(value)
return six.u(str(value.quantize(self.precision, rounding=self.rounding)))

def from_son(self, value):
if value is None:
return None

value = decimal.Decimal(value)

return value.quantize(self.precision, rounding=self.rounding)

def validate(self, value):
if value is None:
return True

try:
value = decimal.Decimal(value)
except:
Expand Down
3 changes: 3 additions & 0 deletions motorengine/fields/url_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class URLField(BaseField):
)

def validate(self, value):
if value is None:
return True

is_url = URLField.URL_REGEX.match(value)

return is_url