src/pyams_utils/schema.py
changeset 436 f7154a8ec9eb
parent 408 cf2304af0fab
equal deleted inserted replaced
435:4504a27af426 436:f7154a8ec9eb
   205 
   205 
   206 
   206 
   207 class InvalidEmail(ValidationError):
   207 class InvalidEmail(ValidationError):
   208     """Invalid email validation error"""
   208     """Invalid email validation error"""
   209 
   209 
   210     __doc__ = _(
   210     __doc__ = _("Email address must be entered as « name@domain.name », without '<' and '>' "
   211         "Email address must be entered as « name@domain.name », without '<' and '>' characters")
   211                 "characters")
   212 
   212 
   213 
   213 
   214 @implementer(IMailAddressField)
   214 @implementer(IMailAddressField)
   215 class MailAddressField(TextLine):
   215 class MailAddressField(TextLine):
   216     """Mail address field"""
   216     """Mail address field"""
   217 
   217 
   218     def _validate(self, value):
   218     def _validate(self, value):
   219         super(MailAddressField, self)._validate(value)
   219         super(MailAddressField, self)._validate(value)
   220         if not EMAIL_REGEX.match(value):
   220         if not EMAIL_REGEX.match(value):
   221             raise InvalidEmail(value)
   221             raise InvalidEmail(value)
       
   222 
       
   223 
       
   224 #
       
   225 # Multiple addresses field
       
   226 #
       
   227 
       
   228 class IMailAddressesListField(ITextLine):
       
   229     """Marker interface for multiple mail addresses list"""
       
   230 
       
   231 
       
   232 class InvalidEmailsList(ValidationError):
       
   233     """Invalid mail addresses list validation error"""
       
   234 
       
   235     __doc__ = _("Email addresses must be entered as « name@domain.name », without '<' and '>' "
       
   236                 "characters, and separated by semicolons")
       
   237 
       
   238 
       
   239 @implementer(IMailAddressesListField)
       
   240 class MailAddressesListField(TextLine):
       
   241     """Mail addresses list field"""
       
   242 
       
   243     def _validate(self, value):
       
   244         super(MailAddressesListField, self)._validate(value)
       
   245         for address in value.split(';'):
       
   246             if not EMAIL_REGEX.match(address.strip()):
       
   247                 raise InvalidEmailsList(value)