當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。