当前位置: 首页>>代码示例>>Python>>正文


Python validators.StopValidation方法代码示例

本文整理汇总了Python中wtforms.validators.StopValidation方法的典型用法代码示例。如果您正苦于以下问题:Python validators.StopValidation方法的具体用法?Python validators.StopValidation怎么用?Python validators.StopValidation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wtforms.validators的用法示例。


在下文中一共展示了validators.StopValidation方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import StopValidation [as 别名]
def __call__(self, form, field):
        if not (isinstance(field.data, FileStorage) and field.data):
            return

        filename = field.data.filename.lower()

        if isinstance(self.upload_set, Iterable):
            if any(filename.endswith('.' + x) for x in self.upload_set):
                return

            raise StopValidation(self.message or field.gettext(
                'File does not have an approved extension: {extensions}'
            ).format(extensions=', '.join(self.upload_set)))

        if not self.upload_set.file_allowed(field.data, filename):
            raise StopValidation(self.message or field.gettext(
                'File does not have an approved extension.'
            )) 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:20,代码来源:file.py

示例2: _run_validation_chain

# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import StopValidation [as 别名]
def _run_validation_chain(self, form, validators):
        """
        Run a validation chain, stopping if any validator raises StopValidation.

        :param form: The Form instance this field beongs to.
        :param validators: a sequence or iterable of validator callables.
        :return: True if validation was stopped, False otherwise.
        """
        for validator in validators:
            try:
                validator(form, self)
            except StopValidation as e:
                if e.args and e.args[0]:
                    self.errors.append(e.args[0])
                return True
            except ValueError as e:
                self.errors.append(e.args[0])

        return False 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:21,代码来源:core.py

示例3: __call__

# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import StopValidation [as 别名]
def __call__(self, form, field):
        if not field.has_file():
            return

        filename = field.data.filename.lower()

        if isinstance(self.upload_set, (tuple, list)):
            ext = filename.rsplit('.', 1)[-1]
            if ext in self.upload_set:
                return
            message = '{} is not in the allowed extentions: {}'.format(
                ext, self.upload_set)
            raise StopValidation(self.message or message)

        if not self.upload_set.file_allowed(field.data, filename):
            raise StopValidation(self.message or
                                 'File does not have an approved extension') 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:file.py

示例4: __call__

# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import StopValidation [as 别名]
def __call__(self, form, field):
        """
        e.g.::

            class SpecialRouteSearchForm(BaseForm):
                special_route = StringField('可为空, 空格, 有值时去除空白', validators=[StripString(allow_none=True)])

            class SpecialRouteForm(BaseForm):
                special_route = StringField('必填, 去除空白赋值', validators=[StripString()])

        """
        fdata = field.data
        if isinstance(fdata, str):
            if self.plain_text:
                fdata = get_plain_text(fdata)
            else:
                fdata = fdata.strip()
        if fdata == '' and not self.allow_none:
            if self.message is None:
                self.message = '{}不能为空{}'.format(field.label.text, '(纯文本)' if self.plain_text else '')
            raise StopValidation(self.message)
        getattr(form, field.name).data = fdata 
开发者ID:fufuok,项目名称:FF.PyAdmin,代码行数:24,代码来源:__init__.py

示例5: validate

# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import StopValidation [as 别名]
def validate(self, form, extra_validators=tuple()):
        """
        Validates the field and returns True or False. `self.errors` will
        contain any errors raised during validation. This is usually only
        called by `Form.validate`.

        Subfields shouldn't override this, but rather override either
        `pre_validate`, `post_validate` or both, depending on needs.

        :param form: The form the field belongs to.
        :param extra_validators: A sequence of extra validators to run.
        """
        self.errors = list(self.process_errors)
        stop_validation = False

        # Call pre_validate
        try:
            self.pre_validate(form)
        except StopValidation as e:
            if e.args and e.args[0]:
                self.errors.append(e.args[0])
            stop_validation = True
        except ValueError as e:
            self.errors.append(e.args[0])

        # Run validators
        if not stop_validation:
            chain = itertools.chain(self.validators, extra_validators)
            stop_validation = self._run_validation_chain(form, chain)

        # Call post_validate
        try:
            self.post_validate(form, stop_validation)
        except ValueError as e:
            self.errors.append(e.args[0])

        return len(self.errors) == 0 
开发者ID:jpush,项目名称:jbox,代码行数:39,代码来源:core.py

示例6: post_validate

# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import StopValidation [as 别名]
def post_validate(self, form, validation_stopped):
        """
        Override if you need to run any field-level validation tasks after
        normal validation. This shouldn't be needed in most cases.

        :param form: The form the field belongs to.
        :param validation_stopped:
            `True` if any validator raised StopValidation.
        """
        pass 
开发者ID:jpush,项目名称:jbox,代码行数:12,代码来源:core.py

示例7: pre_validate

# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import StopValidation [as 别名]
def pre_validate(self, form):
        # If any error happen during process, we raise StopValidation here
        # to prevent "DataRequired" validator from clearing errors
        if self.errors:
            raise validators.StopValidation()
        super(ModelField, self).pre_validate(form) 
开发者ID:opendatateam,项目名称:udata,代码行数:8,代码来源:fields.py

示例8: __call__

# 需要导入模块: from wtforms import validators [as 别名]
# 或者: from wtforms.validators import StopValidation [as 别名]
def __call__(self, form: Dict[str, Any], field: Any) -> None:
        if not form["start_dttm"].data and not form["end_dttm"].data:
            raise StopValidation(_("annotation start time or end time is required."))
        if (
            form["end_dttm"].data
            and form["start_dttm"].data
            and form["end_dttm"].data < form["start_dttm"].data
        ):
            raise StopValidation(
                _("Annotation end time must be no earlier than start time.")
            ) 
开发者ID:apache,项目名称:incubator-superset,代码行数:13,代码来源:annotations.py


注:本文中的wtforms.validators.StopValidation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。