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 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
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)
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)
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 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
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
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
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)
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)
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)
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)
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)
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)