Ed Singleton wrote:
> I'm using a FormEncode Schema to validate a dictionary, and I was
> wondering if it would be easy to get the validator to rename fields on
> the way through?
>
> Something like:
>
> data = {'email': '[EMAIL PROTECTED]'}
>
> class MyValidator(validators.Schema):
> email = validators.Email(not_empty=True, new_field_name='user_email')
>
> my_validator = MyValidator()
>
> valid_data = my_validator.to_python(data)
>
> print valid_data
>
> ## {'user_email': '[EMAIL PROTECTED]'}
You'll need to use a form validator, like:
class RenameField(FormValidator):
def __init__(self, start_name, end_name, **kw):
FormValidator.__init__(
self, start_name=start_name, end_name=end_name, **kw)
def _to_python(self, value, state):
value[end_name] = value[start_name]
def _from_python(self, value, state):
value[start_name] = value[end_name]
class MySchema(Schema):
pre_validators = [RenameField('email', 'user_email')]
--
Ian Bicking | [EMAIL PROTECTED] | http://blog.ianbicking.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---