from wtforms.fields.simple import EmailField
from wtforms.validators import Optional, ValidationError

def antibot_validator(form, field):
    if field.data:
        raise ValidationError('Bas les pattes!')
    return True

class AntibotField(EmailField):

    def __init__(self, *args, **kwargs):
        super().__init__(
            "L'adresse email",
            *args,
            validators=[Optional(), antibot_validator],
            **kwargs)

    def __call__(self, *args, **kwargs):
        return super().__call__(*args, **kwargs,
            class_="abfield", autocomplete="no", tabindex="-1")
