本文整理汇总了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.'))
示例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]
示例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
示例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
示例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'))
示例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
示例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")
示例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")
示例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")
示例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")
示例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')
示例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)
示例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'))
示例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'))
示例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'))