Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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