How to use the wtforms.validators.DataRequired function in WTForms

To help you get started, we’ve selected a few WTForms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LogicJake / WebMonitor / app / main / forms / test_from.py View on Github external
def check_url(form, field):
    url = form.url.data
    try:
        requests.get(url, timeout=10)
    except Exception as e:
        raise ValidationError(repr(e))


class TestForm(FlaskForm):
    url = StringField('监控网址', validators=[DataRequired("请输入网址!"), check_url])
    selector_type = SelectField('元素选择器类型',
                                choices=[('xpath', 'xpath'),
                                         ('css', 'css selector'),
                                         ('json', 'Jsonpath')])
    selector = StringField('元素选择器', validators=[DataRequired("请输入元素选择器!")])
    is_chrome = SelectField('是否使用无头浏览器',
                            choices=[('no', 'no'), ('yes', 'yes')])
    regular_expression = StringField('正则表达式')
    headers = StringField('自定义请求头')
    submit = SubmitField('提取信息')
github Pagure / pagure / tests / test_pagure_flask_ui_remote_pr.py View on Github external
with tests.user_set(self.app.application, user):

            csrf_token = self.get_csrf()
            data = {
                "csrf_token": csrf_token,
                "title": "Remote PR title",
                "branch_from": "feature",
                "branch_to": "master",
                "git_repo": os.path.join(self.newpath, "test"),
            }
            with patch(
                "pagure.forms.RemoteRequestPullForm.git_repo.args",
                MagicMock(
                    return_value=(
                        "Git Repo address",
                        [wtforms.validators.DataRequired()],
                    )
                ),
            ):

                output = self.app.post(
                    "/test/diff/remote", data=data, follow_redirects=True
                )
                self.assertEqual(output.status_code, 200)

                data["confirm"] = 1
                output = self.app.post(
                    "/test/diff/remote", data=data, follow_redirects=True
                )
                self.assertEqual(output.status_code, 200)
                output_text = output.get_data(as_text=True)
                self.assertIn(
github nyaadevs / nyaa / nyaa / forms.py View on Github external
class TorrentFileData(object):
    """Quick and dirty class to pass data from the validator"""

    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)

# https://wiki.theory.org/BitTorrentSpecification#Metainfo_File_Structure


class ReportForm(FlaskForm):
    reason = TextAreaField('Report reason', [
        Length(min=3, max=255,
               message='Report reason must be at least %(min)d characters long '
                       'and %(max)d at most.'),
        DataRequired('You must provide a valid report reason.')
    ])


class ReportActionForm(FlaskForm):
    action = SelectField(choices=[('close', 'Close'), ('hide', 'Hide'), ('delete', 'Delete')])
    torrent = HiddenField()
    report = HiddenField()


def _validate_trackers(torrent_dict, tracker_to_check_for=None):
    announce = torrent_dict.get('announce')
    assert announce is not None, 'no tracker in torrent'
    announce_string = _validate_bytes(announce, 'announce', test_decode='utf-8')

    tracker_found = tracker_to_check_for and (
        announce_string.lower() == tracker_to_check_for.lower()) or False
github PnX-SI / UsersHub / app / bib_organismes / forms.py View on Github external
from flask_wtf import FlaskForm
from wtforms import (StringField, PasswordField, BooleanField, 
    SubmitField, HiddenField, SelectField, TextField, validators
)
from wtforms.validators import DataRequired, Email
# from wtforms_components import IntergerField




class Organisme(FlaskForm):
    """
    Classe du formulaire des Organismes
    """
    nom_organisme = StringField("Nom de l'organisme", validators=[DataRequired(message="Le nom de l'organisme est obligatoire")])
    adresse_organisme = StringField('Adresse')
    cp_organisme = StringField('Code Postal')
    ville_organisme = StringField ('Ville')
    tel_organisme = StringField('Téléphone')
    fax_organisme = StringField('Fax')
    email_organisme = StringField('E-mail', validators=[validators.Optional(), Email(message="L'email est incorect")])
    url_organisme = StringField("URL du site web de l'organisme")
    url_logo = StringField('Logo (URL)')
    id_organisme = HiddenField('id')
    submit = SubmitField('Enregistrer')
github magic-akari / BookLibrary / app / main / auth / forms.py View on Github external
email = StringField('Email',
                        validators=[DataRequired(message=u"该项忘了填写了!"), Length(1, 64), Email(message=u"你确定这是 Email ?")])
    name = StringField(u'用户名', validators=[DataRequired(message=u"该项忘了填写了!"), Length(1, 64)])
    password = PasswordField(u'密码',
                             validators=[DataRequired(message=u"该项忘了填写了!"), EqualTo('password2', message=u'密码必须匹配'),
                                         Length(6, 32)])
    password2 = PasswordField(u'再次确认密码', validators=[DataRequired(message=u"该项忘了填写了!")])
    submit = SubmitField(u'注册')

    def validate_email(self, filed):
        if User.query.filter(db.func.lower(User.email) == db.func.lower(filed.data)).first():
            raise ValidationError(u'该 Email 已经被注册了')


class ChangePasswordForm(FlaskForm):
    old_password = PasswordField(u'旧密码', validators=[DataRequired(message=u"该项忘了填写了!")])
    new_password = PasswordField(u'新密码', validators=[DataRequired(message=u"该项忘了填写了!"),
                                                     EqualTo('confirm_password', message=u'密码必须匹配'),
                                                     Length(6, 32)])
    confirm_password = PasswordField(u'确认新密码', validators=[DataRequired(message=u"该项忘了填写了!")])
    submit = SubmitField(u"保存密码")

    def validate_old_password(self, filed):
        from flask_login import current_user
        if not current_user.verify_password(filed.data):
            raise ValidationError(u'原密码错误')
github TaleLin / lin-cms-flask / app / plugins / poem / app / forms.py View on Github external
class PoemListForm(Form):
    count = IntegerField()
    author = StringField(validators=[Optional()])

    def validate_count(self, row):
        if not row.data:
            return True
        if int(row.data) > 100 or int(row.data) < 1:
            raise ValueError('必须在1~100之间取值')


class PoemSearchForm(Form):
    q = StringField(validators=[
        DataRequired(message='必须传入搜索关键字')
    ])
github pynickle / amazing-python / Tools / english_word / src / forms.py View on Github external
from wtforms import validators
from flask_wtf import FlaskForm
from wtforms import TextAreaField, SubmitField, IntegerField


class SpiderForm(FlaskForm):
    page_number_begin = IntegerField("输入开始页数", [validators.DataRequired()])
    page_number_all = IntegerField("输入爬取页数", [validators.DataRequired(), validators.Length(1, 2240)])
    submit = SubmitField("开始", render_kw = {"class": "button is-link is-outlined is-rounded"})
github longzx-9527 / flask_spider / app / main / forms.py View on Github external
AnyOf 确保输入值在可选值列表中
NoneOf 确保输入值不在可选值列表中
"""


class LoginForm(FlaskForm):
    username = StringField(
        label='用户昵称',
        validators=[
            DataRequired("昵称必填"),
            Length(min=6, max=20, message="用户名必须介于6-20个字符")
        ],
        render_kw={"placeholder": "用户名必须介于6-20个字符"})
    password = PasswordField(
        label="用户密码",
        validators=[DataRequired("密码必填!")],
        render_kw={
            "placeholder": '密码必须大于6个字符',
        })

    remember_me = BooleanField(label='remember_me', default=False)
    submit = SubmitField(label='登录')


class RegisterForm(FlaskForm):
    username = StringField(
        label='用户昵称',
        validators=[
            DataRequired("昵称必填"),
            Length(min=6, max=20, message="用户名必须介于6-20个字符")
        ],
        render_kw={"placeholder": "用户名必须介于6-20个字符"})
github guaosi / flask-movie / app / validators / movie.py View on Github external
from flask_uploads import IMAGES
from flask_wtf import FlaskForm
from flask_wtf.file import FileRequired, FileAllowed
from wtforms import StringField, FileField, IntegerField, DateField
from wtforms.validators import DataRequired, Length, NumberRange, ValidationError
from app.models.movie import Movie as MovieModel
from app.models.tag import Tag
class Movie(FlaskForm):
    id=IntegerField()
    title=StringField(validators=[DataRequired('电影标题必须填写'),Length(min=1,max=255,message='标题长度在1~255之间')])
    url=FileField(validators=[FileRequired('电影文件必须上传'),FileAllowed(['mp4', 'avi','mkv'], '视频格式不正确')])
    info=StringField(validators=[DataRequired('电影简介必须填写')])
    logo=FileField(validators=[FileRequired('电影封面必须上传'),FileAllowed(IMAGES, '图片格式不正确')])
    star=IntegerField(validators=[DataRequired('电影星级必须选择'),NumberRange(min=1,max=5,message='星级在1~5之间')])
    tag_id=IntegerField(validators=[DataRequired('电影标签必须选择')])
    release_time=DateField(validators=[DataRequired('电影上映时间必须选择')])
    length=StringField(validators=[DataRequired('电影时长必须选择')])
    area=StringField(validators=[DataRequired('电影上映地区必须选择')])
    def validate_title(self,field):
        tag=Tag.query.filter_by(id=field.data).first()
        if not tag:
            raise ValidationError('电影标题已存在')
class MovieAddForm(Movie):
    def validate_title(self,field):
        movie=MovieModel.query.filter_by(title=field.data).first()
        if movie:
            raise ValidationError('电影标题已存在')
class MovieEditForm(Movie):
    # 这里让上次文件不是必须字段,然而格式验证还是需要的
    url = FileField(validators=[FileAllowed(['mp4', 'avi', 'mkv'], '视频格式不正确')])
    logo = FileField(validators=[FileAllowed(IMAGES, '图片格式不正确')])