How to use the wtforms.validators.NumberRange 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 orsinium / djburger / tests / validators / pre.py View on Github external
])
    count = wtforms.IntegerField('Count', [
        wtforms.validators.DataRequired(), wtforms.validators.NumberRange(min=0),
    ])


@djburger.validators.wrappers.WTForms
class PreWTFormsWrapped(wtforms.Form):
    name = wtforms.StringField('Name', [
        wtforms.validators.DataRequired(),
    ])
    mail = wtforms.StringField('E-Mail', [
        wtforms.validators.DataRequired(), wtforms.validators.Email(),
    ])
    count = wtforms.IntegerField('Count', [
        wtforms.validators.DataRequired(), wtforms.validators.NumberRange(min=0),
    ])


scheme = dict(
    name=dict(
        type='string',
        required=True,
    ),
    mail=dict(
        type='string',
        required=True,
        # http://docs.python-cerberus.org/en/stable/validation-rules.html#regex
        regex=r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$',
    ),
    count=dict(
        type='integer',
github wtforms / wtforms / tests / test_validators.py View on Github external
def test_lazy_proxy_fixture(really_lazy_proxy):
    """
    Tests that the validators support lazy translation strings for messages.
    """
    equal_to("fieldname", message=really_lazy_proxy)
    length(min=1, message=really_lazy_proxy)
    NumberRange(1, 5, message=really_lazy_proxy)
    data_required(message=really_lazy_proxy)
    regexp(".+", message=really_lazy_proxy)
    email(message=really_lazy_proxy)
    ip_address(message=really_lazy_proxy)
    url(message=really_lazy_proxy)
github kvesteri / wtforms-alchemy / tests / test_forms.py View on Github external
from wtforms_alchemy import (
    ModelCreateForm,
    SelectField,
    model_form_factory,
    null_or_unicode,
)
from .models import User, Location
from tests import MultiDict


class CreateUserForm(ModelCreateForm):
    class Meta:
        model = User
        exclude = ['excluded_field']
        validators = {
            'age': NumberRange(15, 99),
            'description': Length(min=2, max=55),
        }

    deleted_at = DateTimeField()
    overridable_field = BooleanField()


class TestModelFormConfiguration(object):
    def test_inherits_config_params_from_parent_meta(self):
        assert CreateUserForm.Meta.include == []

    def test_child_classes_override_parents_config_params(self):
        assert CreateUserForm.Meta.model == User

    def test_model_form_factory_with_custom_base_class(self):
        class SomeForm(Form):
github Floens / uchan / uchan / view / mod / mod_board.py View on Github external
str(configuration.app.max_boards_per_moderator) + ') boards.')
    submit = SubmitField('Create board')


class BoardConfigurationForm(CSRFForm):
    name = 'Board configuration'

    for_action = HiddenField(default='configuration')

    full_name = StringField('Full name', [Length(max=25)], default='',
                            description='Full name of the board, this is displayed at the top.')
    description = TextAreaField('Description', [Length(max=100)],
                                description='Description of the board, this is displayed below the full name.',
                                render_kw={'cols': 60, 'rows': 6, 'placeholder': 'No description given'})

    pages = IntegerField('Pages', [DataRequired(), NumberRange(min=1, max=15)], default=10,
                         description='Number of pages for this board.')
    per_page = IntegerField('Per page', [DataRequired(), NumberRange(min=10, max=15)], default=15,
                            description='Number of threads per page.')
    bump_limit = IntegerField('Bump limit', [DataRequired(), NumberRange(min=100, max=500)], default=300,
                              description='Max count of posts in a thread that will bump.')
    file_posting = BooleanField('File posting', default=True,
                                description='Toggles file posting. This does not change posts currently '
                                            'up. May be overridden by a site-wide configuration.')
    posting_verification = BooleanField('Posting requires verification', default=False,
                                        description='Require a captcha for posting.')
    max_files = IntegerField('Max files', [DataRequired(), NumberRange(min=1, max=validation.MAX_FILES)], default=3,
                             description='Max number of files you can post per post.')

    submit = SubmitField('Update')
github NVIDIA / DIGITS / digits / dataset / images / classification / forms.py View on Github external
u'Training Images',
        validators=[
            validate_required_iff(method='folder'),
            validate_folder_path,
        ],
        tooltip=('Indicate a folder which holds subfolders full of images. '
                 'Each subfolder should be named according to the desired label for the images that it holds. '
                 'Can also be a URL for an apache/nginx auto-indexed folder.'),
    )

    folder_pct_val = utils.forms.IntegerField(
        u'% for validation',
        default=25,
        validators=[
            validate_required_iff(method='folder'),
            validators.NumberRange(min=0, max=100)
        ],
        tooltip=('You can choose to set apart a certain percentage of images '
                 'from the training images for the validation set.'),
    )

    folder_pct_test = utils.forms.IntegerField(
        u'% for testing',
        default=0,
        validators=[
            validate_required_iff(method='folder'),
            validators.NumberRange(min=0, max=100)
        ],
        tooltip=('You can choose to set apart a certain percentage of images '
                 'from the training images for the test set.'),
    )
github MongoEngine / flask-mongoengine / flask_mongoengine / wtf / orm.py View on Github external
def _number_common(cls, model, field, kwargs):
        if field.max_value or field.min_value:
            kwargs['validators'].append(
                validators.NumberRange(max=field.max_value,
                                       min=field.min_value))
github kizniche / Mycodo / mycodo / mycodo_flask / forms / forms_pid.py View on Github external
widget=NumberInput(step='any')
    )


class PIDModRelayLower(FlaskForm):
    lower_min_duration = DecimalField(
        lazy_gettext('Min On Duration (Lower)'),
        validators=[validators.NumberRange(
            min=0,
            max=86400
        )],
        widget=NumberInput(step='any')
    )
    lower_max_duration = DecimalField(
        lazy_gettext('Max On Duration (Lower)'),
        validators=[validators.NumberRange(
            min=0,
            max=86400
        )],
        widget=NumberInput(step='any')
    )
    lower_min_off_duration = DecimalField(
        lazy_gettext('Min Off Duration (Lower)'),
        validators=[validators.NumberRange(
            min=0,
            max=86400
        )],
        widget=NumberInput(step='any')
    )


class PIDModPWMRaise(FlaskForm):
github veekun / spline-pokedex / splinext / pokedex / controllers / pokedex_gadgets.py View on Github external
c.stats = (stat_query
                   .order_by(t.Stat.id)
                   .all())

        hidden_power_stats = (stat_query
                              .order_by(t.Stat.game_index)
                              .all())

        # Make sure there are the same number of level, stat, and effort
        # fields.  Add an extra one, for adding more data
        num_dupes = c.num_data_points = len(request.GET.getall('level'))
        num_dupes += 1
        class F(StatCalculatorForm):
            level = DuplicateField(
                fields.IntegerField(u'Level', default=100,
                    validators=[wtforms.validators.NumberRange(1, 100)]),
                min_entries=num_dupes,
            )
            stat = DuplicateField(
                StatField(c.stats, fields.IntegerField(default=0, validators=[
                    wtforms.validators.NumberRange(min=0, max=999)])),
                min_entries=num_dupes,
            )
            effort = DuplicateField(
                StatField(c.stats, fields.IntegerField(default=0, validators=[
                    wtforms.validators.NumberRange(min=0, max=255)])),
                min_entries=num_dupes,
            )

        ### Parse form and so forth
        c.form = F(request.GET)
github kizniche / Mycodo / mycodo / mycodo_flask / forms / forms_settings.py View on Github external
#
# Settings (Email)
#

class SettingsEmail(FlaskForm):
    smtp_host = StringField(
        lazy_gettext('SMTP Host'),
        render_kw={"placeholder": lazy_gettext('SMTP Host')},
        validators=[DataRequired()]
    )
    smtp_port = IntegerField(
        lazy_gettext('SMTP Port'),
        render_kw={"placeholder": lazy_gettext('SMTP Port')},
        validators=[validators.NumberRange(
            min=1,
            max=65535,
            message=lazy_gettext('Port should be between 1 and 65535')
        )],
        widget=NumberInput()
    )
    smtp_ssl = BooleanField('Enable SSL')
    smtp_user = StringField(
        lazy_gettext('SMTP User'),
        render_kw={"placeholder": lazy_gettext('SMTP User')},
        validators=[DataRequired()]
    )
    smtp_password = PasswordField(
        lazy_gettext('SMTP Password'),
        render_kw={"placeholder": TRANSLATIONS['password']['title']}
    )
github Yubico / yubiadmin / yubiadmin / apps / val.py View on Github external
('old_limit', yk_handler('SYNC_OLD_LIMIT', 10)),
        ('sync_pool', yk_array_handler('SYNC_POOL')),
        ('allowed_sync_pool', yk_array_handler('ALLOWED_SYNC_POOL')),
        ('ksm_urls', KSMHandler())
    ]
)


class SyncLevelsForm(ConfigForm):
    legend = 'Sync Levels'
    description = 'Percentage of syncing required for pre-defined levels.'
    config = ykval_config

    sync_default = IntegerField('Default Level', [NumberRange(1, 100)])
    sync_secure = IntegerField('Secure Level', [NumberRange(1, 100)])
    sync_fast = IntegerField('Fast Level', [NumberRange(1, 100)])


class MiscForm(ConfigForm):
    legend = 'Misc'
    config = ykval_config

    default_timeout = IntegerField('Default Timeout (seconds)',
                                   [NumberRange(0)])


class DaemonForm(ConfigForm):
    legend = 'Daemon Settings'
    config = ykval_config
    sync_interval = IntegerField(
        'Sync Interval', [NumberRange(1)],
        description='How often (in seconds) to sync with other server.')