Пример #1
0
def collection_entity_save(collection):
    collection = get_collection(collection, authz.WRITE)
    data = request_data()
    update_operation = 'id' in data

    entities = get_loom_config().entities
    schema = data.get('$schema')
    if update_operation and schema is None:
        schema = entities.get_schema(data['id'], right=authz.entity_right())

    if schema not in get_loom_config().schemas.values():
        raise BadRequest()

    # this will raise if it fails:
    validate(data, schema)
    subject = entities.save(schema, data, collection_id=collection.id,
                            author=request.auth_user,
                            right=authz.entity_right())
    collection_add_entity(collection, subject)
    get_loom_indexer().index_one(subject, schema=schema)
    entity = entities.get(subject, schema=schema, depth=2,
                          right=authz.entity_right())
    return jsonify({
        'status': 'ok',
        'data': entity
    }, status=200 if update_operation else 201)
Пример #2
0
def collection_entity_save(collection):
    collection = get_collection(collection, authz.WRITE)
    data = request_data()
    update_operation = 'id' in data

    entities = get_loom_config().entities
    schema = data.get('$schema')
    if update_operation and schema is None:
        schema = entities.get_schema(data['id'], right=authz.entity_right())

    if schema not in get_loom_config().schemas.values():
        raise BadRequest()

    # this will raise if it fails:
    validate(data, schema)
    subject = entities.save(schema,
                            data,
                            collection_id=collection.id,
                            author=request.auth_user,
                            right=authz.entity_right())
    collection_add_entity(collection, subject)
    get_loom_indexer().index_one(subject, schema=schema)
    entity = entities.get(subject,
                          schema=schema,
                          depth=2,
                          right=authz.entity_right())
    return jsonify({
        'status': 'ok',
        'data': entity
    },
                   status=200 if update_operation else 201)
Пример #3
0
def collection_entities(collection, depth=2, filter_schema=None):
    config = get_loom_config()
    # FIXME: this is a performance nightmare. Think about how to fix it.
    results = []
    q = config.entities.subjects(schema=filter_schema,
                                 collection_id=collection.id,
                                 right=authz.entity_right())
    for (subject, schema) in q:
        data = config.entities.get(subject, schema=schema, depth=depth,
                                   right=authz.entity_right())
        results.append(result_entity(data))
    return results
Пример #4
0
def collection_entities(collection, depth=2, filter_schema=None):
    config = get_loom_config()
    # FIXME: this is a performance nightmare. Think about how to fix it.
    results = []
    q = config.entities.subjects(schema=filter_schema,
                                 collection_id=collection.id,
                                 right=authz.entity_right())
    for (subject, schema) in q:
        data = config.entities.get(subject,
                                   schema=schema,
                                   depth=depth,
                                   right=authz.entity_right())
        results.append(result_entity(data))
    return results
Пример #5
0
def view(id):
    entities = get_loom_config().entities
    data = obj_or_404(entities.get(id, depth=get_depth(3),
                                   right=authz.entity_right()))
    return jsonify({'status': 'ok', 'data': result_entity(data)})
Пример #6
0
def view(id):
    entities = get_loom_config().entities
    data = obj_or_404(
        entities.get(id, depth=get_depth(3), right=authz.entity_right()))
    return jsonify({'status': 'ok', 'data': result_entity(data)})