我在Deform/漏斗中实现了一个简单的“tick to agree to terms and conditions”框。
因此,我只想检查该框是否已选中,并且有一条错误消息说“您必须同意T&C”。
我知道我可以使用:
colander.OneOf([True]) 以确保该框已勾选。但是,OneOf不允许自定义错误消息。这样做的正确方法是什么?
发布于 2011-07-22 03:45:28
使用自定义验证器:
def t_and_c_validator(node, value):
if not value:
raise Invalid(node, 'You must agree to the T&C')
class MySchema(colander.Schema):
t_and_c = colander.SchemaNode(
colander.Boolean(),
description='Terms and Conditions',
widget=deform.widget.CheckboxWidget(),
title='Terms and Conditions',
validator=t_and_c_validator,
)https://stackoverflow.com/questions/6775005
复制相似问题