def _normalize_field(form, field): email = u'@' in field.data if email: # normalize email address casing if not allow_email: raise wtforms.ValidationError(nomail_msg) wtforms.validators.Email()(form, field) field.data = normalize_email(field.data) else: # lower case user names if not allow_user: raise wtforms.ValidationError(nouser_msg) wtforms.validators.Length(min=3, max=30)(form, field) wtforms.validators.Regexp(r'^[-_\w]+$')(form, field) field.data = field.data.lower() if field.data is None: # should not happen, but be cautious anyway raise wtforms.ValidationError(message)
def _normalize_field(form, field): email = u'@' in field.data if email: # normalize email address casing if not allow_email: raise wtforms.ValidationError(nomail_msg) wtforms.validators.Email()(form, field) field.data = normalize_email(field.data) else: # lower case user names if not allow_user: raise wtforms.ValidationError(nouser_msg) wtforms.validators.Length(min=3, max=30)(form, field) wtforms.validators.Regexp(r'^\w+$')(form, field) field.data = field.data.lower() if field.data is None: # should not happen, but be cautious anyway raise wtforms.ValidationError(message)