本文整理汇总了Python中flask_wtf.FlaskForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python FlaskForm.validate方法的具体用法?Python FlaskForm.validate怎么用?Python FlaskForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_wtf.FlaskForm
的用法示例。
在下文中一共展示了FlaskForm.validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
# Validate all other fields with default validators
if not FlaskForm.validate(self):
return False
result = True
archive_date = self.archive_date.data
publish_date = self.publish_date.data
if archive_date and publish_date > archive_date:
self.archive_date.errors.append(
_('Archive date needs to be after the publish date.'))
result = False
# Test if either english or dutch is entered
if not (self.nl_title.data or self.en_title.data):
self.nl_title.errors.append(
_('Either Dutch or English title required'))
result = False
if not (self.nl_content.data or self.en_content.data):
self.nl_content.errors.append(
_('Either Dutch or English content required'))
result = False
# XOR the results to test if both of a language was given
if bool(self.nl_title.data) != bool(self.nl_content.data):
self.nl_title.errors.append(
_('Dutch title requires Dutch content and vice versa'))
result = False
if bool(self.en_title.data) != bool(self.en_content.data):
self.en_title.errors.append(
_('English title requires English content and vice versa'))
result = False
return result
示例2: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
rv = FlaskForm.validate(self)
if not rv:
return False
if len(str(self.postalcode.data)) is 5 and int(self.postalcode.data):
return True
self.postalcode.data = re.sub(r'\s', r'', self.postalcode.data)
if not len(str(self.postalcode.data)) is 6:
self.postalcode.errors.append('Invalid postal code (length)')
return False
if not ''.join([
str(self.postalcode.data)[0],
str(self.postalcode.data)[2],
str(self.postalcode.data)[4]
]).isalpha():
self.postalcode.errors.append(
'Invalid postal code (example: A1A1A1)'
)
return False
if not ''.join([
str(self.postalcode.data)[1],
str(self.postalcode.data)[3],
str(self.postalcode.data)[5]
]).isdigit():
self.postalcode.errors.append(
'Invalid postal code (example: A1A1A1)'
)
return False
return True
示例3: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
rv = FlaskForm.validate(self)
if rv is None:
return False
user = authenticate_user(current_user.username, self.password.data)
if user is None:
return False
return True
示例4: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
if not FlaskForm.validate(self):
return False
user = User.query.filter_by(email = self.email.data.lower()).first()
if user:
self.email.errors.append("That email is already taken")
return False
else:
return True
示例5: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
if not Form.validate(self):
return False
if self.username.data == self.original_username:
return True
user = User.query.filter_by(username = self.username.data).first()
if user != None:
return False
return True
示例6: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
if not FlaskForm.validate(self):
return False
if self.open.data:
self.desired_state = DoorState.Open
elif self.present.data:
self.desired_state = DoorState.Present
return True
示例7: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
rv = FlaskForm.validate(self)
if not rv:
return False
user = User.get_user(self.username.data)
if user and user.username.lower() != g.user.username.lower():
self.username.errors.append('Username already in use')
return False
return True
示例8: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
rv = Form.validate(self)
if not rv:
return False
captcha = session['captcha']
captcha_data = self.captcha.data
if captcha_data.lower() != captcha.lower():
self.captcha.errors.append(_('The captcha is error'))
return False
return True
示例9: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
# check default validation
if not FlaskForm.validate(self):
return False
# check nested forms
for t in self.target_set:
if not t.form.validate():
error_fields = ','.join(t.form.errors.keys())
self.target_set.errors.append({'target': t.name, 'message': 'Invalid target ' + error_fields})
return False
return True
示例10: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
if not FlaskForm.validate(self):
print "wrong two"
return False
user = User.query.filter_by(username=self.username.data).first()
if user and user.verify_password(self.password_hash.data):
return True
else:
flash('invalid username or password')
self.username.errors.append("Invalid username or password")
return False
示例11: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
# Validate all other fields with default validators
if not FlaskForm.validate(self):
return False
# Test if either english or dutch is entered
if self.start_time.data >= self.end_time.data:
self.start_time.errors.append(
_("Start time must be before end time"))
# Append empty string to mark the field red.
self.end_time.errors.append('')
return False
return True
示例12: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self, *args, **kwargs):
"""
Validates the form by calling `validate` on each field, passing any
extra `Form.validate_<fieldname>` validators to the field validator.
also calls `validate_ldap`
"""
valid = FlaskForm.validate(self, *args, **kwargs)
if not valid:
logging.debug("Form validation failed before we had a change to "
"check ldap. Reasons: '{0}'".format(self.errors))
return valid
return self.validate_ldap()
示例13: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
rv = FlaskForm.validate(self)
if not rv:
return False
if self.action.data not in ('edit', 'new'):
return False
has_error = False
if self.action.data in ('edit', 'new'):
if type(self.name.data) not in (str, unicode) or not re.search(r'[A-Za-z0-9]', self.name.data):
self.name.errors.append(word("The name must be filled in."))
has_error = True
if type(self.method.data) not in (str, unicode) or self.method.data not in ('referer', 'ip', 'none'):
self.name.errors.append(word("You must select an option."))
has_error = True
if has_error:
return False
return True
示例14: validate
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def validate(self):
if request.form.get('message'): # super simple bot test (advanced bots will get by this)
log.warning("Suspect form submission from (put IP here), ignoring")
abort(404)
return FlaskForm.validate(self)
示例15: skip
# 需要导入模块: from flask_wtf import FlaskForm [as 别名]
# 或者: from flask_wtf.FlaskForm import validate [as 别名]
def skip():
assert g.get('csrf_valid')
# don't pass the token, then validate the form
# this would fail if CSRFProtect didn't run
form = FlaskForm(None)
assert form.validate()