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


Python validators.ValidationError方法代碼示例

本文整理匯總了Python中wtforms.validators.ValidationError方法的典型用法代碼示例。如果您正苦於以下問題:Python validators.ValidationError方法的具體用法?Python validators.ValidationError怎麽用?Python validators.ValidationError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wtforms.validators的用法示例。


在下文中一共展示了validators.ValidationError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: validate_email

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def validate_email(self, email):
        """Ensure no duplicate emails."""
        user = User.query.filter_by(email=email.data).first()
        if user is not None:
            raise ValidationError(_('Please use a different email address.'))
        white_listed_email = None
        if current_app.config["ALLOWED_EMAIL_LIST"]:
            white_listed_email_list = current_app.config["ALLOWED_EMAIL_LIST"]
            for item in white_listed_email_list:
                item_length = len(item)
                test_email = self.email.data[-item_length:]
                user_email_address_domain = item[-item_length:]
                if user_email_address_domain == test_email:
                    white_listed_email = True
            if not white_listed_email:
                raise ValidationError(_('Please use a whitelisted email address.')) 
開發者ID:AUCR,項目名稱:AUCR,代碼行數:18,代碼來源:forms.py

示例2: fetch_objects

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def fetch_objects(self, oids):
        '''
        This methods is used to fetch models
        from a list of identifiers.

        Default implementation performs a bulk query on identifiers.

        Override this method to customize the objects retrieval.
        '''
        objects = self.model.objects.in_bulk(oids)
        if len(objects.keys()) != len(oids):
            non_existants = set(oids) - set(objects.keys())
            msg = _('Unknown identifiers: {identifiers}').format(
                identifiers=', '.join(str(ne) for ne in non_existants))
            raise validators.ValidationError(msg)

        return [objects[id] for id in oids] 
開發者ID:opendatateam,項目名稱:udata,代碼行數:19,代碼來源:fields.py

示例3: process_formdata

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def process_formdata(self, valuelist):
        if valuelist and valuelist[0]:
            value = valuelist[0]
            if isinstance(value, str):
                start, end = value.split(' - ')
                self.data = db.DateRange(
                    start=parse(start, yearfirst=True).date(),
                    end=parse(end, yearfirst=True).date(),
                )
            elif 'start' in value and 'end' in value:
                self.data = db.DateRange(
                    start=parse(value['start'], yearfirst=True).date(),
                    end=parse(value['end'], yearfirst=True).date(),
                )
            else:
                raise validators.ValidationError(
                    _('Unable to parse date range'))
        else:
            self.data = None 
開發者ID:opendatateam,項目名稱:udata,代碼行數:21,代碼來源:fields.py

示例4: pre_validate

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def pre_validate(self, form):
        if self.data:
            if not current_user.is_authenticated:
                raise validators.ValidationError(
                    _('You must be authenticated'))
            elif not OrganizationPrivatePermission(self.data).can():
                raise validators.ValidationError(
                    _("Permission denied for this organization"))
            # Ensure either owner field or this field value is unset
            owner_field = form._fields[self.owner_field]
            if self.raw_data:
                owner_field.data = None
            elif getattr(form._obj, self.short_name) and not owner_field.data:
                pass
            else:
                self.data = None
        return True 
開發者ID:opendatateam,項目名稱:udata,代碼行數:19,代碼來源:fields.py

示例5: process_formdata

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def process_formdata(self, valuelist):
        if valuelist:
            date_str = ' '.join(valuelist)
            if not date_str:
                self.data = None
                raise ValidationError(self.gettext('Please input a date/time value'))

            parse_kwargs = self.parse_kwargs.copy()
            if 'default' not in parse_kwargs:
                try:
                    parse_kwargs['default'] = self.default()
                except TypeError:
                    parse_kwargs['default'] = self.default
            try:
                self.data = parser.parse(date_str, **parse_kwargs)
            except ValueError:
                self.data = None
                raise ValidationError(self.gettext('Invalid date/time input')) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:20,代碼來源:fields.py

示例6: pre_validate

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def pre_validate(self, form):
        invalid_dict, invalid_json = False, False
        try:
            result = loads(self.data)
        except Exception:
            invalid_json = True
        if self.json_only and invalid_json:
            raise ValidationError("Invalid json syntax.")
        try:
            result = literal_eval(self.data)
        except Exception:
            invalid_dict = True
        if invalid_dict and invalid_json:
            raise ValidationError("Invalid dictionary syntax.")
        if not isinstance(result, dict) and not self.json_only:
            raise ValidationError("This field only accepts dictionaries.")
        if app.contains_set(result):
            raise ValidationError("Sets are not allowed.")
        return True 
開發者ID:eNMS-automation,項目名稱:eNMS,代碼行數:21,代碼來源:fields.py

示例7: validate_trade_account

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def validate_trade_account(self, trade_account):
        acc = trade_account.data
        if acc == "":
            raise ValidationError("Trade Account cannot be empty") 
開發者ID:pxsocs,項目名稱:thewarden,代碼行數:6,代碼來源:forms.py

示例8: validate_trade_asset_ticker

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def validate_trade_asset_ticker(self, trade_asset_ticker):
        ticker = trade_asset_ticker.data
        if ticker == "":
            raise ValidationError("Ticker cannot be empty") 
開發者ID:pxsocs,項目名稱:thewarden,代碼行數:6,代碼來源:forms.py

示例9: validate_trade_price

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def validate_trade_price(self, trade_price):
        try:
            price = float(trade_price.data)
        except ValueError:
            raise ValidationError("Invalid Price")
        if price < 0:
            raise ValidationError("Price has to be a positive number")
        if price == "":
            raise ValidationError("Price can't be empty") 
開發者ID:pxsocs,項目名稱:thewarden,代碼行數:11,代碼來源:forms.py

示例10: validate_trade_quantity

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def validate_trade_quantity(self, trade_quantity):
        try:
            quant = float(trade_quantity.data)
        except ValueError:
            raise ValidationError("Invalid Quantity")
        if quant < 0:
            raise ValidationError("Quantity has to be a positive number")
        if quant == "":
            raise ValidationError("Quantity can't be empty") 
開發者ID:pxsocs,項目名稱:thewarden,代碼行數:11,代碼來源:forms.py

示例11: __call__

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def __call__(self, form, field):
        if form.target_type.data != 'global':
            if field.data is None or len(field.data.strip()) == 0:
                raise ValidationError('Need target ID if type is not global ban') 
開發者ID:thenetcircle,項目名稱:dino,代碼行數:6,代碼來源:__init__.py

示例12: __call__

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def __call__(self, form, email):
        if not isinstance(email.data, six.text_type):
            raise validators.ValidationError(
                "Email fields should be of text type. Found {0}".format(
                    type(email.data)
                )
            )
        elif not re.match(r"[^@]+@[^@]+\.[^@]+", email.data):
            raise validators.ValidationError(self._message) 
開發者ID:Pagure,項目名稱:pagure,代碼行數:11,代碼來源:validators.py

示例13: validate_csrf_token

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def validate_csrf_token(self, form, field):
        """
        Override this method to provide custom CSRF validation logic.

        The default CSRF validation logic simply checks if the recently
        generated token equals the one we received as formdata.

        :param form: The form which has this CSRF token.
        :param field: The CSRF token field.
        """
        if field.current_token != field.data:
            raise ValidationError(field.gettext('Invalid CSRF Token')) 
開發者ID:jpush,項目名稱:jbox,代碼行數:14,代碼來源:core.py

示例14: pre_validate

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def pre_validate(self, form):
        data = self.data
        if data is not None:
            for pk, obj in self._get_object_list():
                if data == obj:
                    break
            else:
                raise ValidationError(self.gettext('Not a valid choice'))
        elif self._formdata or not self.allow_blank:
            raise ValidationError(self.gettext('Not a valid choice')) 
開發者ID:jpush,項目名稱:jbox,代碼行數:12,代碼來源:fields.py

示例15: pre_validate

# 需要導入模塊: from wtforms import validators [as 別名]
# 或者: from wtforms.validators import ValidationError [as 別名]
def pre_validate(self, form):
        if not self.allow_blank or self.data is not None:
            for obj in self.queryset:
                if self.data == obj:
                    break
            else:
                raise ValidationError(self.gettext('Not a valid choice')) 
開發者ID:jpush,項目名稱:jbox,代碼行數:9,代碼來源:fields.py


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