當前位置: 首頁>>代碼示例>>Python>>正文


Python validators.Optional方法代碼示例

本文整理匯總了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) 
開發者ID:jpush,項目名稱:jbox,代碼行數:28,代碼來源:orm.py

示例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 
開發者ID:radremedy,項目名稱:radremedy,代碼行數:34,代碼來源:reviewview.py

示例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 
開發者ID:radremedy,項目名稱:radremedy,代碼行數:32,代碼來源:resourceview.py


注:本文中的wtforms.validators.Optional方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。