Michael Jenny
2012-07-21 18:09:08 UTC
Hi there,
i have a schema validator and want to use another compound validator
(SimpleFormValidator) from within the schema.
E.g. I do something along the lines:
def validate_text(value_dict, state, validator):
# validation of text_field goes here. check value_dict for
bool_field's value to determine what to do next.
class ProductConfigurationSchema(Schema):
filter_extra_fields = True
allow_extra_fields = True
bool_field = validators.Bool()
text_field = SimpleFormValidator(validate_text)
This does not work as the schema does not expect that its fields are
compound validators. It doesn't pass the value_dict to the
SimpleFormValidator but rather a single value. This results in the
following errror in SimpleFormValidators to_python method:
value_dict = value_dict.copy()
AttributeError: 'unicode' object has no attribute 'copy'
I followed that route because I want to achieve the following:
The visibility of the text_field depends on the bool_field. Therefore I'd
thought I write a custom method that checks the state of the bool when
validating the text_field. If it is set, I would perform the actual
validation. If the bool is not set, the text_field is irrelevant and
validating would essentially be a no-op.
Any tip how to tackle this?
Cheers, prinz.
i have a schema validator and want to use another compound validator
(SimpleFormValidator) from within the schema.
E.g. I do something along the lines:
def validate_text(value_dict, state, validator):
# validation of text_field goes here. check value_dict for
bool_field's value to determine what to do next.
class ProductConfigurationSchema(Schema):
filter_extra_fields = True
allow_extra_fields = True
bool_field = validators.Bool()
text_field = SimpleFormValidator(validate_text)
This does not work as the schema does not expect that its fields are
compound validators. It doesn't pass the value_dict to the
SimpleFormValidator but rather a single value. This results in the
following errror in SimpleFormValidators to_python method:
value_dict = value_dict.copy()
AttributeError: 'unicode' object has no attribute 'copy'
I followed that route because I want to achieve the following:
The visibility of the text_field depends on the bool_field. Therefore I'd
thought I write a custom method that checks the state of the bool when
validating the text_field. If it is set, I would perform the actual
validation. If the bool is not set, the text_field is irrelevant and
validating would essentially be a no-op.
Any tip how to tackle this?
Cheers, prinz.