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


Python FlaskForm.validate方法代碼示例

本文整理匯總了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
開發者ID:viaict,項目名稱:viaduct,代碼行數:37,代碼來源:news.py

示例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
開發者ID:BenChaimberg,項目名稱:swingflask,代碼行數:31,代碼來源:forms.py

示例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
開發者ID:zifnab06,項目名稱:zifb.in,代碼行數:10,代碼來源:auth.py

示例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
開發者ID:AlvinCJin,項目名稱:RealEstateApp,代碼行數:11,代碼來源:forms.py

示例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
開發者ID:glorysongglory,項目名稱:flask_demo,代碼行數:11,代碼來源:forms.py

示例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
開發者ID:Binary-Kitchen,項目名稱:doorlockd,代碼行數:12,代碼來源:WebApp.py

示例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
開發者ID:axula,項目名稱:pfcharactersheet,代碼行數:13,代碼來源:forms.py

示例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
開發者ID:honmaple,項目名稱:maple-bbs,代碼行數:14,代碼來源:forms.py

示例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
開發者ID:18mr,項目名稱:call-congress,代碼行數:15,代碼來源:forms.py

示例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
開發者ID:eddwinn,項目名稱:searchAnon,代碼行數:15,代碼來源:forms.py

示例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
開發者ID:viaict,項目名稱:viaduct,代碼行數:17,代碼來源:activity.py

示例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()
開發者ID:mwielgoszewski,項目名稱:flask-ldap3-login,代碼行數:17,代碼來源:forms.py

示例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
開發者ID:Gauntlet173,項目名稱:docassemble,代碼行數:19,代碼來源:develop.py

示例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)
開發者ID:drytoastman,項目名稱:wwscc,代碼行數:7,代碼來源:forms.py

示例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()
開發者ID:lepture,項目名稱:flask-wtf,代碼行數:8,代碼來源:test_csrf_extension.py


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