本文整理汇总了Python中wtforms.validators.NumberRange方法的典型用法代码示例。如果您正苦于以下问题:Python validators.NumberRange方法的具体用法?Python validators.NumberRange怎么用?Python validators.NumberRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wtforms.validators
的用法示例。
在下文中一共展示了validators.NumberRange方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_integer_types
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import NumberRange [as 别名]
def handle_integer_types(self, column, field_args, **extra):
unsigned = getattr(column.type, 'unsigned', False)
if unsigned:
field_args['validators'].append(validators.NumberRange(min=0))
return f.IntegerField(**field_args)
示例2: conv_MSYear
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import NumberRange [as 别名]
def conv_MSYear(self, field_args, **extra):
field_args['validators'].append(validators.NumberRange(min=1901, max=2155))
return f.TextField(**field_args)
示例3: get_IntegerField
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import NumberRange [as 别名]
def get_IntegerField(kwargs):
"""
Returns an ``IntegerField``, applying the ``ndb.IntegerProperty`` range
limits.
"""
v = validators.NumberRange(min=-0x8000000000000000, max=0x7fffffffffffffff)
kwargs['validators'].append(v)
return f.IntegerField(**kwargs)
示例4: get_IntegerField
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import NumberRange [as 别名]
def get_IntegerField(kwargs):
"""
Returns an ``IntegerField``, applying the ``db.IntegerProperty`` range
limits.
"""
v = validators.NumberRange(min=-0x8000000000000000, max=0x7fffffffffffffff)
kwargs['validators'].append(v)
return f.IntegerField(**kwargs)
示例5: convert_RatingProperty
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import NumberRange [as 别名]
def convert_RatingProperty(model, prop, kwargs):
"""Returns a form field for a ``db.RatingProperty``."""
kwargs['validators'].append(validators.NumberRange(min=0, max=100))
return f.IntegerField(**kwargs)
示例6: scaffold_form
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import NumberRange [as 别名]
def scaffold_form(self):
"""
Sets up the review form to ensure that the rating field
behaves on a 1-5 scale.
"""
form_class = super(ReviewView, self).scaffold_form()
form_class.rating = IntegerField(
review_column_labels['rating'],
validators=[
validators.Required(),
validators.NumberRange(min=1, max=5)
]
)
form_class.staff_rating = IntegerField(
review_column_labels['staff_rating'],
validators=[
validators.Optional(),
validators.NumberRange(min=1, max=5)
]
)
form_class.intake_rating = IntegerField(
review_column_labels['intake_rating'],
validators=[
validators.Optional(),
validators.NumberRange(min=1, max=5)
]
)
return form_class
示例7: get_field_args
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import NumberRange [as 别名]
def get_field_args(field, **kwargs):
"""
Generates a dictionary of arguments to be used when
rendering out a form field.
Args:
field: The form field to render.
**kwargs: Any additional arguments to include for the form field.
Returns:
A dictionary of arguments to use to render out a form field.
"""
# Set up our default args
field_args = {
"class_": "form-control"
}
# Handle required fields
if field.flags.required:
field_args['required'] = 'required'
# Look at field validators
for val in field.validators:
# Handle minlength/maxlength attributes if specified on
# string fields through a Length validator
if isinstance(val, Length):
if val.min > 0:
field_args['minlength'] = val.min
if val.max > 0:
field_args['maxlength'] = val.max
elif isinstance(val, Email):
field_args['type'] = 'email'
elif isinstance(val, URL):
field_args['type'] = 'url'
elif isinstance(val, NumberRange):
if val.min is not None:
field_args['min'] = val.min
if val.max is not None:
field_args['max'] = val.max
# If we have a description, create an aria-described by attribute
if field.description and len(field.description) > 0:
field_args['aria-describedby'] = field.id + '_help'
# Merge in extra arguments
field_args.update(kwargs)
# Default rows for textareas if not specified
if 'rows' not in field_args and field.type == 'TextAreaField':
field_args['rows'] = '3'
return field_args