Made Arrow and IPAddress types use ScalarCoercible

This commit is contained in:
Konsta Vesterinen
2013-10-24 11:31:04 +03:00
parent 7dc71d2719
commit 576edb19a5
2 changed files with 6 additions and 4 deletions

View File

@@ -10,9 +10,10 @@ except:
pass
from sqlalchemy import types
from sqlalchemy_utils import ImproperlyConfigured
from .scalar_coercible import ScalarCoercible
class ArrowType(types.TypeDecorator):
class ArrowType(types.TypeDecorator, ScalarCoercible):
impl = types.DateTime
def __init__(self, *args, **kwargs):
@@ -33,7 +34,7 @@ class ArrowType(types.TypeDecorator):
return arrow.get(value)
return value
def coercion_listener(self, target, value, oldvalue, initiator):
def _coerce(self, value):
if value is None:
return None
elif isinstance(value, six.string_types):

View File

@@ -12,9 +12,10 @@ except ImportError:
from sqlalchemy import types
from sqlalchemy_utils import ImproperlyConfigured
from .scalar_coercible import ScalarCoercible
class IPAddressType(types.TypeDecorator):
class IPAddressType(types.TypeDecorator, ScalarCoercible):
"""
Changes IPAddress objects to a string representation on the way in and
changes them back to IPAddress objects on the way out.
@@ -38,5 +39,5 @@ class IPAddressType(types.TypeDecorator):
def process_result_value(self, value, dialect):
return ip_address(value) if value else None
def coercion_listener(self, target, value, oldvalue, initiator):
def _coerce(self, value):
return ip_address(value) if value else None