How to use the wtforms.validators.ValidationError function in WTForms

To help you get started, we’ve selected a few WTForms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wtforms / wtforms / tests / test_validators.py View on Github external
def test_bad_ip6address_raises(address, dummy_form, dummy_field):
    adr = ip_address()
    dummy_field.data = address
    with pytest.raises(ValidationError):
        adr(dummy_form, dummy_field)
github arXiv / arxiv-search / search / controllers / util.py View on Github external
def does_not_start_with_wildcard(form: Form, field: StringField) -> None:
    """Check that ``value`` does not start with a wildcard character."""
    if not field.data:
        return
    if field.data.startswith('?') or field.data.startswith('*'):
        raise validators.ValidationError(
            'Search cannot start with a wildcard (? *).')
    if any([part.startswith('?') or part.startswith('*')
            for part in field.data.split()]):
        raise validators.ValidationError('Search terms cannot start with a'
                                         ' wildcard (? *).')
github luoyun / LuoYunCloud / lyweb / app / admin / forms.py View on Github external
def password_confirm(form, field):
    if field.data != form.password_confirm.data:
        raise ValidationError('password confirm failed')
github flaskbb / flaskbb / flaskbb / management / forms.py View on Github external
def validate_avatar(self, field):
        if field.data is not None:
            error, status = check_image(field.data)
            if error is not None:
                raise ValidationError(error)
            return status
github indico / indico / indico / modules / events / registration / forms.py View on Github external
def _check_if_payment_required(form, field):
    if not field.data:
        return
    if not is_feature_enabled(form.event, 'payment'):
        raise ValidationError(_('You have to enable the payment feature in order to set a registration fee.'))
github Raibows / NCEPU-CS-COURSES / DatabaseExp / BookManagementSystem / app / auth / forms.py View on Github external
def book_insert_num(form, field):
    message = '单次添加数量必须为正整数,且小于1000'
    if field.data:
        try:
            data = int(field.data)
        except:
            raise ValidationError(message)
        else:
            if data < 0 or data > 999:
                raise ValidationError(message)
github inveniosoftware / invenio / invenio / modules / messages / forms.py View on Github external
def validate_user_nicks(form, field):
    """Find not valid users."""
    if field.data:
        test = set(msg_split_addr(field.data))
        comp = set([u for u, in db.session.query(User.nickname).
                    filter(User.nickname.in_(test)).all()])
        diff = test.difference(comp)
        if len(diff) > 0:
            raise validators.ValidationError(
                _('Not valid users: %{diff}s', diff=', '.join(diff)))
github pypa / warehouse / warehouse / accounts / forms.py View on Github external
def validate_totp_value(self, field):
        totp_value = field.data.encode("utf8")

        if not self.user_service.check_totp_value(self.user_id, totp_value):
            raise wtforms.validators.ValidationError(_("Invalid TOTP code."))
github TwilioDevEd / authy2fa-flask / twofa / auth / forms.py View on Github external
def validate_unique_email(form, field):
    """Validates that an email address hasn't been registered already"""
    if User.query.filter_by(email=field.data).count() > 0:
        raise validators.ValidationError('This email address has already been registered.')
github eleweek / WatchPeopleCode / app.py View on Github external
def validate_youtube_channel(form, field):
        yc = form.youtube_channel_extract()
        if yc is None:
            # fixme. add explanation here or hint to page
            raise ValidationError("This field should contain valid youtube channel.")

        streamer = Streamer.query.filter_by(youtube_channel=yc).first()
        if streamer and streamer.checked and streamer != current_user:
            raise ValidationError("There is another user with this channel. If it is your channel, please message about that to r/WatchPeoplecode moderators.")