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 query_schema(context):
    query = mapping('query')
    query.add(
        key('name',
            validator=chained(nonempty_string, available_slug(context),
                              slug_name)))
    query.add(key('label', validator=chained(nonempty_string)))
    query.add(key('query', validator=chained(nonempty_string)))
    return query
Exemplo n.º 3
0
def entity_schema(schema):
    entity = mapping('entity')
    entity.add(key('title', validator=chained(
            nonempty_string
        )))
    entity.add(key('type', validator=chained(
            nonempty_string,
            in_([schema.name])
        )))
    return apply_schema(entity, schema)
Exemplo n.º 4
0
def validate_account(data, context):
    schema = mapping('account', validator=chained(confirmed_password))
    schema.add(
        key('name',
            validator=chained(nonempty_string, slug_name,
                              available_name(context))))
    schema.add(key('email', validator=nonempty_string))
    schema.add(key('password', validator=nonempty_string))
    schema.add(key('password_repeat', validator=nonempty_string))
    schema.add(key('fullname', missing=None))
    return schema.deserialize(data)
Exemplo n.º 5
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.º 6
0
def attribute_schema(name, meta):
    """ Validate the representation of a schema attribute. """
    schema = mapping(name,
                     validator=chained(
                         name_wrap(nonempty_string, name),
                         name_wrap(reserved_name(INVALID_NAMES), name),
                         name_wrap(database_name, name)))
    schema.add(key('label', validator=nonempty_string))
    schema.add(key('missing', missing=None))
    schema.add(
        key('type',
            validator=chained(nonempty_string, in_(ATTRIBUTE_TYPES_DB))))
    return schema
Exemplo n.º 7
0
def query_schema(context):
    query = mapping('query')
    query.add(key('name', validator=chained(
            nonempty_string,
            available_slug(context),
            slug_name
        )))
    query.add(key('label', validator=chained(
            nonempty_string
        )))
    query.add(key('query', validator=chained(
            nonempty_string
        )))
    return query
Exemplo n.º 8
0
def attribute_schema(name, meta):
    """ Validate the representation of a schema attribute. """
    schema = mapping(name, validator=chained(
        name_wrap(nonempty_string, name),
        name_wrap(reserved_name(INVALID_NAMES), name),
        name_wrap(database_name, name)
        ))
    schema.add(key('label', validator=nonempty_string))
    schema.add(key('missing', missing=None))
    schema.add(key('type', validator=chained(
            nonempty_string,
            in_(ATTRIBUTE_TYPES_DB)
        )))
    return schema
Exemplo n.º 9
0
def validate_account(data, context):
    schema = mapping('account', validator=chained(
        confirmed_password
        ))
    schema.add(key('name', validator=chained(
            nonempty_string,
            slug_name,
            available_name(context)
        )))
    schema.add(key('email', validator=nonempty_string))
    schema.add(key('password', validator=nonempty_string))
    schema.add(key('password_repeat', validator=nonempty_string))
    schema.add(key('fullname', missing=None))
    return schema.deserialize(data)
Exemplo n.º 10
0
def validate_schema(data):
    """ Validate a schema. This does not actually apply the
    schema to user data but checks for the integrity of its
    specification. """
    schema = mapping('schema')
    schema.add(
        key('name',
            validator=chained(
                nonempty_string,
                reserved_name(INVALID_NAMES),
                database_name,
            )))
    schema.add(key('label', validator=chained(nonempty_string, )))
    attributes = mapping('attributes')
    for attribute, meta in data.get('attributes', {}).items():
        attributes.add(attribute_schema(attribute, meta))
    schema.add(attributes)
    return schema.deserialize(data)
Exemplo n.º 11
0
def validate_schema(data):
    """ Validate a schema. This does not actually apply the
    schema to user data but checks for the integrity of its
    specification. """
    schema = mapping('schema')
    schema.add(key('name', validator=chained(
            nonempty_string,
            reserved_name(INVALID_NAMES),
            database_name,
        )))
    schema.add(key('label', validator=chained(
            nonempty_string,
        )))
    attributes = mapping('attributes')
    for attribute, meta in data.get('attributes', {}).items():
        attributes.add(attribute_schema(attribute, meta))
    schema.add(attributes)
    return schema.deserialize(data)
Exemplo n.º 12
0
def validate_network(data, context):
    network = mapping('network')
    network.add(
        key('slug',
            validator=chained(nonempty_string, slug_name,
                              available_slug(context))))
    network.add(key('title', validator=nonempty_string))
    network.add(key('description', missing=None))
    if not 'slug' in data:
        data['slug'] = slugify(data.get('title', ''))
    return network.deserialize(data)
Exemplo n.º 13
0
def validate_network(data, context):
    network = mapping('network')
    network.add(key('slug', validator=chained(
            nonempty_string,
            slug_name,
            available_slug(context)
        )))
    network.add(key('title', validator=nonempty_string))
    network.add(key('description', missing=None))
    if not 'slug' in data:
        data['slug'] = slugify(data.get('title', ''))
    return network.deserialize(data)
Exemplo n.º 14
0
def entity_schema(schema):
    entity = mapping('entity')
    entity.add(key('title', validator=chained(nonempty_string)))
    entity.add(
        key('type', validator=chained(nonempty_string, in_([schema.name]))))
    return apply_schema(entity, schema)