Allow setting custom length to EmailType, refs #229
This commit is contained in:
@@ -4,9 +4,12 @@ from ..operators import CaseInsensitiveComparator
|
||||
|
||||
|
||||
class EmailType(sa.types.TypeDecorator):
|
||||
impl = sa.Unicode(255)
|
||||
impl = sa.Unicode
|
||||
comparator_factory = CaseInsensitiveComparator
|
||||
|
||||
def __init__(self, length=255, *args, **kwargs):
|
||||
super(EmailType, self).__init__(length=length, *args, **kwargs)
|
||||
|
||||
def process_bind_param(self, value, dialect):
|
||||
if value is not None:
|
||||
return value.lower()
|
||||
|
@@ -10,6 +10,7 @@ def User(Base):
|
||||
__tablename__ = 'user'
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
email = sa.Column(EmailType)
|
||||
short_email = sa.Column(EmailType(length=70))
|
||||
|
||||
def __repr__(self):
|
||||
return 'User(%r)' % self.id
|
||||
@@ -30,3 +31,6 @@ class TestEmailType(object):
|
||||
clause = User.email == 'Someone@example.com'
|
||||
compiled = str(clause.compile(compile_kwargs={'literal_binds': True}))
|
||||
assert compiled == '"user".email = lower(\'Someone@example.com\')'
|
||||
|
||||
def test_custom_length(self, session, User):
|
||||
assert User.short_email.type.impl.length == 70
|
||||
|
Reference in New Issue
Block a user