def relation_schema(schema, context, ignore_entities=False): relation = mapping('relation', validator=chained(source_not_target)) relation.add( key('type', validator=chained(nonempty_string, in_([schema.name])))) if not ignore_entities: relation.add(_node(EntitySchemaType(context), 'source')) relation.add(_node(EntitySchemaType(context), 'target')) return apply_schema(relation, schema)
def relation_schema(schema, context, ignore_entities=False): relation = mapping('relation', validator=chained( source_not_target )) relation.add(key('type', validator=chained( nonempty_string, in_([schema.name]) ))) if not ignore_entities: relation.add(_node(EntitySchemaType(context), 'source')) relation.add(_node(EntitySchemaType(context), 'target')) return apply_schema(relation, schema)
def apply_schema(base, schema): """ Apply the required attributes of a given schema to an existing schema. """ for attribute in schema.attributes: validator = ATTRIBUTE_VALIDATORS[attribute.type] missing = attribute.missing if validator == colander.Boolean: missing = missing or "0" base.add(_node(validator(), attribute.name, missing=attribute.missing, empty=attribute.missing)) return base
def apply_schema(base, schema): """ Apply the required attributes of a given schema to an existing schema. """ for attribute in schema.attributes: validator = ATTRIBUTE_VALIDATORS[attribute.type] missing = attribute.missing if validator == colander.Boolean: missing = missing or "0" base.add( _node(validator(), attribute.name, missing=attribute.missing, empty=attribute.missing)) return base