Skip to content

Commit

Permalink
Update validators.py
Browse files Browse the repository at this point in the history
 - Add Docstring
 - Add default message
  • Loading branch information
qurbat committed Jan 14, 2020
1 parent aeeb33c commit 7a3331b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions baseframe/forms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,22 @@ class NotEqualTo(_Comparison):
def compare(self, value, other):
return value != other

class IsEmoji(object):
"""
Validate that field.data does not belong to a public email domain.
If the domain lookup fails and mxsniff raises ``MXLookupException``, this validator
will still pass, as we expect that most domains are not public email domains.
:param message:
Error message to raise in case of a validation error.
"""
def __init__(self, message=None):
self.message = message or _(u'This is not a valid emoji.')

def __call__(self, form, field):
if not field.data in emoji.UNICODE_EMOJI:
raise ValidationError(self.message)


class IsPublicEmailDomain(object):
"""
Expand All @@ -321,15 +337,6 @@ def __call__(self, form, field):
else:
raise ValidationError(self.message)

class IsEmoji(object):

def __init__(self, message=None):
self.message = message

def __call__(self, form, field):
if not field.data in emoji.UNICODE_EMOJI:
raise ValidationError(self.message)


class IsNotPublicEmailDomain(object):
"""
Expand Down

0 comments on commit 7a3331b

Please sign in to comment.