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


Python Form.errors_for方法代码示例

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


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

示例1: location_add

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors_for [as 别名]
def location_add(request):
    form = Form(request, schema=LocationSchema())
    if form.validate():
        location = form.bind(models.Location())
        with transaction.manager:
           models.DBSession.add(location)
        locations = models.DBSession.query(models.Location).all()
        locations_list = [(location.id, location.name)  for location in locations]
        return {"page": "Locations", "items": locations_list, "headings": headings}
    else:
       print form.all_errors()
       print form.errors_for('parent')
       print "Form validation failed"
开发者ID:etoko,项目名称:longitudinal_register,代码行数:15,代码来源:locations.py

示例2: test_errors_for

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors_for [as 别名]
    def test_errors_for(self):
        from pyramid_simpleform import Form

        request = testing.DummyRequest()
        request.method = "POST"

        form = Form(request, SimpleFESchema)

        self.assert_(not(form.validate()))
        self.assert_(form.is_validated)
        self.assert_('name' in form.errors)

        self.assert_(form.errors_for('name') == ['Missing value'])
开发者ID:Mr-F,项目名称:pyramid_simpleform,代码行数:15,代码来源:tests.py

示例3: test_validate_bad_input_with_validators

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors_for [as 别名]
    def test_validate_bad_input_with_validators(self):
        from pyramid_simpleform import Form

        request = testing.DummyRequest()
        request.method = "POST"

        form = Form(request, validators=dict(name=validators.NotEmpty()))

        self.assert_(not form.validate())
        self.assert_(form.is_validated)
        self.assert_(form.is_error("name"))

        self.assert_(form.errors_for("name") == ["Please enter a value"])
开发者ID:GoodRx,项目名称:pyramid_simpleform,代码行数:15,代码来源:tests.py

示例4: ModelState

# 需要导入模块: from pyramid_simpleform import Form [as 别名]
# 或者: from pyramid_simpleform.Form import errors_for [as 别名]
class ModelState(object):
    def __init__(self, request):
        self.form = Form(request)
        self.renderer = CiocFormRenderer(self.form)
        self._defaults = None

    @property
    def is_valid(self):
        return not self.form.errors

    @property
    def schema(self):
        return self.form.schema

    @schema.setter
    def schema(self, value):
        if self.form.schema:
            raise RuntimeError("schema property has already been set")
        self.form.schema = value

    @property
    def validators(self):
        return self.form.validators

    @validators.setter
    def validators(self, value):
        if self.form.validators:
            raise RuntimeError("validators property has alread been set")

        self.form.validators = value

    @property
    def method(self):
        return self.form.method

    @method.setter
    def method(self, value):
        self.form.method = value

    @property
    def defaults(self):
        return self._defaults

    @defaults.setter
    def defaults(self, value):
        if self._defaults:
            raise RuntimeError("defaults property has already been set")

        if self.form.is_validated:
            raise RuntimeError("Form has already been validated")
        self._defaults = value
        self.form.data.update(value)

    @property
    def data(self):
        return self.form.data

    def validate(self, *args, **kw):
        return self.form.validate(*args, **kw)

    def bind(self, obj=None, include=None, exclude=None):
        if obj is None:
            obj = DefaultModel()

        return self.form.bind(obj, include, exclude)

    def value(self, name, default=None):
        return self.renderer.value(name, default)

    def is_error(self, name):
        return self.renderer.is_error(name)

    def errors(self):
        return self.form.errors

    def errors_for(self, name):
        return self.renderer.errors_for(name)

    def add_error_for(self, name, msg):
        errlist = self.form.errors_for(name)
        errlist.append(msg)

        self.form.errors[name] = errlist
开发者ID:OpenCIOC,项目名称:offlinetools,代码行数:85,代码来源:modelstate.py


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