Esempio n. 1
0
class AddForm(SecureForm):
    offerer = wtf_fields.StringField(
        "Offreur",
        validators=[wtf_validators.DataRequired()],
        widget=widgets.AutocompleteSelectWidget(endpoint="/pc/back-office/autocomplete/offerers", getter=get_offerers),
    )
    subcategories = fields.SelectMultipleFieldWithOptgroups(
        "Sous-catégories",
        description="Laissez vide si toutes les sous-catégories sont concernées ; sélectionnez les sous-catégories souhaitées sinon. Pour sélectionner plusieurs sous-catégories, gardez appuyées les touches <Cmd> et/ou <Majuscule> sur Mac, et les touches <Ctrl> et/ou <majuscule> sur PC.",
        size=10,
        choices=SUBCATEGORY_CHOICES,
    )
    rate = wtf_fields.IntegerField(
        "Taux de remboursement (%)",
        description='Un taux de remboursement (en pourcentage), compris entre 0 et 100. Par exemple, pour 95%, saisir "95"',
        validators=[
            wtf_validators.DataRequired(),
            wtf_validators.NumberRange(0, 100, message="Le taux doit être compris entre %(min)s et %(max)s."),
        ],
    )
    start_date = wtf_html5_fields.DateField(
        "Date de début d'application",
        description="Cette date ne peut pas être antérieure à demain.",
        validators=[wtf_validators.DataRequired()],
        widget=widgets.DateInputWithConstraint(
            min_date=lambda _field: datetime.date.today() + datetime.timedelta(days=1)
        ),
    )
    end_date = wtf_html5_fields.DateField(
        "Date de fin d'application (optionnelle)",
        validators=[wtf_validators.Optional()],
        widget=widgets.DateInputWithConstraint(
            min_date=lambda _field: datetime.date.today() + datetime.timedelta(days=2)
        ),
    )
class RequestResetForm(flask_wtf.form.FlaskForm):
    """Class representing the user password reset request form for the
    application

    Parameters
    ----------
    FlaskForm : WTForms

        Flask wtf class that is extended to create the user login form
    """

    email = wtforms_core.StringField(
        "Email",
        validators=[
            wtforms.validators.DataRequired(),
            wtforms.validators.Email(),
        ],
    )
    submit = wtforms_simple.SubmitField("Request password reset")

    def validate_email(self, email):
        """Validate if the given email is still available against the DB

        Parameters
        ----------
        email : string

            email as entered in the form.
        """
        user = flaskblog_user.User.query.filter_by(email=email.data).first()
        if user is None:
            raise wtforms.validators.ValidationError(
                "There is no account with this email. You must register first."
            )
Esempio n. 3
0
class UserForm(Form):
    # 静态字段,实例化只执行一次
    city = core.StringField(
        label='城市',
        choices = (),   #从数据库取数据
    )
    name = simple.StringField(label='姓名')

    def __init__(self,*args,**kwargs):
        super(UserForm,self).__init__(*args,**kwargs)

        self.city.choices = '从数据库取数据'
Esempio n. 4
0
class PostForm(flask_wtf.FlaskForm):
    """Class representing the blog post form for the application

    Parameters
    ----------
    FlaskForm : WTForms

        Flask wtf class that is extended to create the user login form
    """

    title = wtforms_core.StringField(
        "Title", validators=[wtforms.validators.DataRequired()]
    )
    content = wtforms_simple.TextAreaField(
        "Content", validators=[wtforms.validators.DataRequired()]
    )
    submit = wtforms_simple.SubmitField("Post")
Esempio n. 5
0
class StudentForm(Form):
    ID = simple.StringField(widget=widgets.HiddenInput),
    StudentName = simple.StringField(
        label="姓名",
        validators=[
            validators.data_required(message="学生姓名不能为空!"),
            validators.Length(min=2, max=20, message="学生姓名长度必须大于2位,小于20位")
        ])
    Age = core.StringField(label="年龄",
                           validators=[
                               validators.data_required(message="学生年龄不能为空!"),
                               validators.Regexp(regex="^\d+$",
                                                 message="学生年龄必须为数字")
                           ])
    Gender = core.RadioField(
        label="性别",
        coerce=int,  # 保存到数据中的值为int类型
        choices=((0, '女'), (1, '男')),
        default=1)
    submit = simple.SubmitField(label="提交")
class LoginForm(flask_wtf.FlaskForm):
    """Class representing the login form for the application

    Parameters
    ----------
    FlaskForm : WTForms

        Flask wtf class that is extended to create the user login form
    """

    email = wtforms_core.StringField(
        "Email",
        validators=[
            wtforms.validators.DataRequired(),
            wtforms.validators.Email(),
        ],
    )
    password = wtforms_simple.PasswordField(
        "Password", validators=[wtforms.validators.DataRequired()]
    )
    remember = wtforms_core.BooleanField("Remember Me")
    submit = wtforms_simple.SubmitField("Login")
Esempio n. 7
0
class RegistrationForm(flask_wtf.FlaskForm):
    """Class representing the registration form for the application

    Parameters
    ----------
    FlaskForm : WTForms

        Flask wtf class that is extended to create the user login form
    """

    username = wtforms_core.StringField(
        "Username",
        validators=[
            wtforms.validators.DataRequired(),
            wtforms.validators.Length(min=2, max=20),
        ],
    )
    email = wtforms_core.StringField(
        "Email",
        validators=[
            wtforms.validators.DataRequired(),
            wtforms.validators.Email(),
        ],
    )
    password = wtforms_simple.PasswordField(
        "Password", validators=[wtforms.validators.DataRequired()])
    confirm_password = wtforms_simple.PasswordField(
        "Confirm Password",
        validators=[
            wtforms.validators.DataRequired(),
            wtforms.validators.EqualTo("password"),
        ],
    )
    submit = wtforms_simple.SubmitField("Sign Up")

    def validate_username(self, username):
        """Validate if the given username is still available against the DB

        Parameters
        ----------
        username : string

            Username as entered in the form.
        """
        user = flaskblog_user.User.query.filter_by(
            username=username.data).first()
        if user:
            raise wtforms.validators.ValidationError(
                "That username is taken. Please choose a different one")

    def validate_email(self, email):
        """Validate if the given email is still available against the DB

        Parameters
        ----------
        email : string

            email as entered in the form.
        """
        user = flaskblog_user.User.query.filter_by(email=email.data).first()
        if user:
            raise wtforms.validators.ValidationError(
                "That email address is taken. Please choose a different one")
Esempio n. 8
0
class UserForm(Form):
    name = core.StringField(label='用户名',
                            validators=[validators.DataRequired()])
    email = core.StringField(label='邮箱',
                             validators=[validators.DataRequired()])
class UpdateAccountForm(flask_wtf.FlaskForm):
    """Class representing the account update form for the application

    Parameters
    ----------
    FlaskForm : WTForms

        Flask wtf class that is extended to create the user login form
    """

    username = wtforms_core.StringField(
        "Username",
        validators=[
            wtforms.validators.DataRequired(),
            wtforms.validators.Length(min=2, max=20),
        ],
    )
    email = wtforms_core.StringField(
        "Email",
        validators=[
            wtforms.validators.DataRequired(),
            wtforms.validators.Email(),
        ],
    )
    picture = flask_file.FileField(
        "Update profile picture",
        validators=[flask_file.FileAllowed(["jpg", "png"])],
    )
    submit = wtforms_simple.SubmitField("Update")

    def validate_username(self, username):
        """Validate if the given username is still available against the DB

        Parameters
        ----------
        username : string

            Username as entered in the form.
        """
        if username.data != flask_login.current_user.username:
            user = flaskblog_user.User.query.filter_by(
                username=username.data
            ).first()
            if user:
                raise wtforms.validators.ValidationError(
                    "That username is taken. Please choose a different one"
                )

    def validate_email(self, email):
        """Validate if the given email is still available against the DB

        Parameters
        ----------
        email : string

            email as entered in the form.
        """
        if email.data != flask_login.current_user.email:
            user = flaskblog_user.User.query.filter_by(
                email=email.data
            ).first()
            if user:
                raise wtforms.validators.ValidationError(
                    "That email address is taken. Please choose a different one"
                )