本文整理汇总了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"
示例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'])
示例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"])
示例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