当前位置: 首页>>代码示例>>Python>>正文


Python form.Form方法代码示例

本文整理汇总了Python中wtforms.form.Form方法的典型用法代码示例。如果您正苦于以下问题:Python form.Form方法的具体用法?Python form.Form怎么用?Python form.Form使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wtforms.form的用法示例。


在下文中一共展示了form.Form方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: field_async_run_validation_chain

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def field_async_run_validation_chain(self, form, validators):
    """
    Run a validation chain, stopping if any validator raises StopValidation.

    :param form: The Form instance this field beongs to.
    :param validators: a sequence or iterable of validator callables.
    :return: True if validation was stopped, False otherwise.
    """
    for validator in validators:
        try:
            yield validator(form, self)
        except StopValidation as e:
            if e.args and e.args[0]:
                self.errors.append(e.args[0])
            return True
        except ValueError as e:
            self.errors.append(e.args[0])

    return False 
开发者ID:tornado-lightmagic,项目名称:wtforms-lightmagic,代码行数:21,代码来源:form.py

示例2: __init__

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def __init__(self, *args, **kwargs):
        warnings.warn(
            'i18n is now in core, wtforms.ext.i18n will be removed in WTForms 3.0',
            DeprecationWarning, stacklevel=2
        )
        if 'LANGUAGES' in kwargs:
            self.LANGUAGES = kwargs.pop('LANGUAGES')
        super(Form, self).__init__(*args, **kwargs) 
开发者ID:snverse,项目名称:Sci-Finder,代码行数:10,代码来源:form.py

示例3: test_birthday_field

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def test_birthday_field():
    class F(Form):
        birthday = BirthdayField(format='%d %m %Y')

    a = ["04 02 2015"]
    b = ["None", "None", "2015"]  # this one should fail
    c = ["None", "None", "None"]

    form = F()

    assert form.birthday.process_formdata(a) is None
    assert form.birthday.process_formdata(c) is None

    with pytest.raises(ValueError):
        form.birthday.process_formdata(b) 
开发者ID:python-security,项目名称:pyt,代码行数:17,代码来源:test_fields.py

示例4: __init__

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def __init__(self, *args, **kwargs):
        if 'LANGUAGES' in kwargs:
            self.LANGUAGES = kwargs.pop('LANGUAGES')
        super(Form, self).__init__(*args, **kwargs) 
开发者ID:RoseOu,项目名称:flasky,代码行数:6,代码来源:form.py

示例5: __init__

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def __init__(self, *args, **kwargs):
        warnings.warn('i18n is now in core, wtforms.ext.i18n will be removed in WTForms 3.0', DeprecationWarning)
        if 'LANGUAGES' in kwargs:
            self.LANGUAGES = kwargs.pop('LANGUAGES')
        super(Form, self).__init__(*args, **kwargs) 
开发者ID:sunqb,项目名称:oa_qian,代码行数:7,代码来源:form.py

示例6: __init__

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def __init__(self, formdata=None, obj=None, prefix='', locale_code='en_US',
             **kwargs):
        self._locale_code = locale_code
        super(Form, self).__init__(formdata, obj, prefix, **kwargs) 
开发者ID:tornado-lightmagic,项目名称:wtforms-lightmagic,代码行数:6,代码来源:form.py

示例7: process

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def process(self, formdata=None, obj=None, **kwargs):
        if formdata is not None and not hasattr(formdata, 'getlist'):
            formdata = TornadoInputWrapper(formdata)
        super(Form, self).process(formdata, obj, **kwargs) 
开发者ID:tornado-lightmagic,项目名称:wtforms-lightmagic,代码行数:6,代码来源:form.py

示例8: async_validate

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def async_validate(self):
        """
        Validates the form by calling `async_validate` on each field, passing any
        extra `Form.async_validate_<fieldname>` validators to the field validator.
        """
        extra = {}
        for name in self._fields:
            inline = getattr(self.__class__, 'async_validate_%s' % name, None)
            if inline is not None:
                extra[name] = [inline]

        res = yield self.async_validate_extra(extra)

        return res 
开发者ID:tornado-lightmagic,项目名称:wtforms-lightmagic,代码行数:16,代码来源:form.py

示例9: field_async_validate

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def field_async_validate(self, form, extra_validators=tuple()):
    """
    Validates the field and returns True or False. `self.errors` will
    contain any errors raised during validation. This is usually only
    called by `Form.validate`.

    Subfields shouldn't override this, but rather override either
    `pre_validate`, `post_validate` or both, depending on needs.

    :param form: The form the field belongs to.
    :param extra_validators: A sequence of extra validators to run.
    """
    if not self.errors:
        self.errors = list(self.process_errors)
    stop_validation = False

    # Call async_pre_validate
    try:
        yield self.async_pre_validate(form)
    except StopValidation as e:
        if e.args and e.args[0]:
            self.errors.append(e.args[0])
        stop_validation = True
    except ValueError as e:
        self.errors.append(e.args[0])

    # Run async validators
    if not stop_validation:
        chain = itertools.chain(self.async_validators, extra_validators)
        stop_validation = yield self.async_run_validation_chain(form, chain)

    # Call post_validate
    try:
        yield self.async_post_validate(form, stop_validation)
    except ValueError as e:
        self.errors.append(e.args[0])

    return len(self.errors) == 0 
开发者ID:tornado-lightmagic,项目名称:wtforms-lightmagic,代码行数:40,代码来源:form.py

示例10: model_form

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def model_form(model, db_session=None, base_class=Form, only=None,
               exclude=None, field_args=None, converter=None, exclude_pk=True,
               exclude_fk=True, type_name=None):
    """
    Create a wtforms Form for a given SQLAlchemy model class::

        from wtforms.ext.sqlalchemy.orm import model_form
        from myapp.models import User
        UserForm = model_form(User)

    :param model:
        A SQLAlchemy mapped model class.
    :param db_session:
        An optional SQLAlchemy Session.
    :param base_class:
        Base form class to extend from. Must be a ``wtforms.Form`` subclass.
    :param only:
        An optional iterable with the property names that should be included in
        the form. Only these properties will have fields.
    :param exclude:
        An optional iterable with the property names that should be excluded
        from the form. All other properties will have fields.
    :param field_args:
        An optional dictionary of field names mapping to keyword arguments used
        to construct each field object.
    :param converter:
        A converter to generate the fields based on the model properties. If
        not set, ``ModelConverter`` is used.
    :param exclude_pk:
        An optional boolean to force primary key exclusion.
    :param exclude_fk:
        An optional boolean to force foreign keys exclusion.
    :param type_name:
        An optional string to set returned type name.
    """
    if not hasattr(model, '_sa_class_manager'):
        raise TypeError('model must be a sqlalchemy mapped model')

    type_name = type_name or str(model.__name__ + 'Form')
    field_dict = model_fields(
        model, db_session, only, exclude, field_args, converter,
        exclude_pk=exclude_pk, exclude_fk=exclude_fk
    )
    return type(type_name, (base_class, ), field_dict) 
开发者ID:snverse,项目名称:Sci-Finder,代码行数:46,代码来源:orm.py

示例11: model_form

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def model_form(model, db_session=None, base_class=Form, only=None,
    exclude=None, field_args=None, converter=None, exclude_pk=True,
    exclude_fk=True, type_name=None):
    """
    Create a wtforms Form for a given SQLAlchemy model class::

        from wtalchemy.orm import model_form
        from myapp.models import User
        UserForm = model_form(User)

    :param model:
        A SQLAlchemy mapped model class.
    :param db_session:
        An optional SQLAlchemy Session.
    :param base_class:
        Base form class to extend from. Must be a ``wtforms.Form`` subclass.
    :param only:
        An optional iterable with the property names that should be included in
        the form. Only these properties will have fields.
    :param exclude:
        An optional iterable with the property names that should be excluded
        from the form. All other properties will have fields.
    :param field_args:
        An optional dictionary of field names mapping to keyword arguments used
        to construct each field object.
    :param converter:
        A converter to generate the fields based on the model properties. If
        not set, ``ModelConverter`` is used.
    :param exclude_pk:
        An optional boolean to force primary key exclusion.
    :param exclude_fk:
        An optional boolean to force foreign keys exclusion.
    :param type_name:
        An optional string to set returned type name.
    """
    if not hasattr(model, '_sa_class_manager'):
        raise TypeError('model must be a sqlalchemy mapped model')

    if not exclude:
        exclude = []
    model_mapper = model.__mapper__
    for prop in model_mapper.iterate_properties:
        if not hasattr(prop, 'direction') and prop.columns[0].primary_key:
            if exclude_pk:
                exclude.append(prop.key)
        if hasattr(prop, 'direction') and exclude_fk and \
                prop.direction.name != 'MANYTOMANY':
            for pair in prop.local_remote_pairs:
                exclude.append(pair[0].key)
    type_name = type_name or str(model.__name__ + 'Form')
    field_dict = model_fields(model, db_session, only, exclude, field_args, converter)
    return type(type_name, (base_class, ), field_dict) 
开发者ID:RoseOu,项目名称:flasky,代码行数:54,代码来源:orm.py

示例12: model_form

# 需要导入模块: from wtforms import form [as 别名]
# 或者: from wtforms.form import Form [as 别名]
def model_form(model, db_session=None, base_class=Form, only=None,
               exclude=None, field_args=None, converter=None, exclude_pk=True,
               exclude_fk=True, type_name=None):
    """
    Create a wtforms Form for a given SQLAlchemy model class::

        from wtalchemy.orm import model_form
        from myapp.models import User
        UserForm = model_form(User)

    :param model:
        A SQLAlchemy mapped model class.
    :param db_session:
        An optional SQLAlchemy Session.
    :param base_class:
        Base form class to extend from. Must be a ``wtforms.Form`` subclass.
    :param only:
        An optional iterable with the property names that should be included in
        the form. Only these properties will have fields.
    :param exclude:
        An optional iterable with the property names that should be excluded
        from the form. All other properties will have fields.
    :param field_args:
        An optional dictionary of field names mapping to keyword arguments used
        to construct each field object.
    :param converter:
        A converter to generate the fields based on the model properties. If
        not set, ``ModelConverter`` is used.
    :param exclude_pk:
        An optional boolean to force primary key exclusion.
    :param exclude_fk:
        An optional boolean to force foreign keys exclusion.
    :param type_name:
        An optional string to set returned type name.
    """
    if not hasattr(model, '_sa_class_manager'):
        raise TypeError('model must be a sqlalchemy mapped model')

    type_name = type_name or str(model.__name__ + 'Form')
    field_dict = model_fields(
        model, db_session, only, exclude, field_args, converter,
        exclude_pk=exclude_pk, exclude_fk=exclude_fk
    )
    return type(type_name, (base_class, ), field_dict) 
开发者ID:sunqb,项目名称:oa_qian,代码行数:46,代码来源:orm.py


注:本文中的wtforms.form.Form方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。