class FieldsSchema(validators.Schema): chained_validators = [validators.FieldsMatch('passwd', 'passwd2')] name = validators.UnicodeString() age = validators.Int() passwd = validators.NotEmpty() passwd2 = validators.UnicodeString()
class UserEditSchema(validators.Schema): """ separate validation schema from the fields definition make it possible to define a more complex schema that involves field dependency or logical operators """ user_name = validators.String(not_empty=True, max=16) status = validators.OneOf(['ENABLED', 'LOCKED', 'DISABLED']) password = validators.UnicodeString(max=50) password_confirm = validators.UnicodeString(max=50) chained_validators = [ validators.FieldsMatch('password', 'password_confirm') ]
class FieldsSchema(validators.Schema): chained_validators = [validators.FieldsMatch('passwd', 'passwd2')]