Basically I'm struggling to add a multi-field validation error generated by on a child schema to the parent schema. Here goes...
I have a schema which includes a subschema:
class SubSchema(Colander.Schema):
url = colander.SchemaNode(...)
description = colander.SchemaNode(...)
class MainSchema(Colander.Schema):
sub_node = SubSchema()
...
I also have a validation function that checks that at least one of 'url' and 'description' is non-null:
def sub_schema_validator(form, value):
if not value['url'] and not value['description']:
exc = colander.Invalid(form, 'Must enter either a website or a description')
exc['url'] = ''
exc['description'] = 'Please enter either a website or a description'
raise exc
This function works fine if I just use the sub-schema (no main schema). For the main schema, I've tried to write a function that calls the sub-schema validation function:
def main_schema_validator(form, value):
subnode = child_named('sub_node', form)
sub_schema_validator(subnode, value['sub_node'])
The error gets raised, but the 'url' and 'description' fields don't get highlighted like they should be. I'm not sure how I'm supposed to add the exception generated by the sub-node to one for the main node.
Any ideas?