本文整理汇总了Python中wtforms.validators.Optional方法的典型用法代码示例。如果您正苦于以下问题:Python validators.Optional方法的具体用法?Python validators.Optional怎么用?Python validators.Optional使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wtforms.validators
的用法示例。
在下文中一共展示了validators.Optional方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import Optional [as 别名]
def convert(self, model, field, field_args):
kwargs = {
'label': field.verbose_name,
'description': field.help_text,
'validators': [],
'filters': [],
'default': field.default,
}
if field_args:
kwargs.update(field_args)
if field.blank:
kwargs['validators'].append(validators.Optional())
if field.max_length is not None and field.max_length > 0:
kwargs['validators'].append(validators.Length(max=field.max_length))
ftype = type(field).__name__
if field.choices:
kwargs['choices'] = field.choices
return f.SelectField(**kwargs)
elif ftype in self.converters:
return self.converters[ftype](model, field, kwargs)
else:
converter = getattr(self, 'conv_%s' % ftype, None)
if converter is not None:
return converter(model, field, kwargs)
示例2: scaffold_form
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import Optional [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
示例3: scaffold_resource_form
# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import Optional [as 别名]
def scaffold_resource_form(form_class):
"""
Scaffolds the provided resource form class by ensuring
location fields are optional and that nullable flag fields
are actually handled as nullable.
Args:
form_class: The form class to update.
column_labels: The column labels to use.
Returns:
The updated form class.
"""
# Override the latitude/longitude fields to be optional
form_class.latitude = DecimalField(validators=[validators.Optional()])
form_class.longitude = DecimalField(validators=[validators.Optional()])
# Override the nullable flag fields to actually be nullable -
# otherwise, Flask-Admin treats them as standard Boolean fields
# (which is bad - we want the N/A option)
form_class.is_wpath = NullableBooleanField(
label=resource_column_labels['is_wpath'])
form_class.is_icath = NullableBooleanField(
label=resource_column_labels['is_icath'])
form_class.is_accessible = NullableBooleanField(
label=resource_column_labels['is_accessible'])
form_class.has_sliding_scale = NullableBooleanField(
label=resource_column_labels['has_sliding_scale'])
return form_class