示例#1
0
def load_ba_fixtures(config):
    # This is messy. Would be cool to do it more cleanly, but how?
    if not len(BA_FIXTURES['entities']):
        with open(os.path.join(FIXTURES, 'ba.mapping.yaml'), 'rb') as fh:
            mapping = yaml.load(fh)
        mapper = Mapper(mapping, config.resolver, scope=config.base_uri)
        with open(os.path.join(FIXTURES, 'ba.csv'), 'rb') as csvfh:
            reader = unicodecsv.DictReader(csvfh)
            for row in reader:
                _, data = mapper.apply(row)
                BA_FIXTURES['entities'].append(data)

    source = Source.ensure({
        'slug': BA_SOURCE,
        'title': 'BiH Parliament',
        'url': 'http://foo.ba/'
    })
    permission = Permission()
    permission.role_id = Role.SYSTEM_USER
    permission.read = True
    permission.write = False
    permission.resource_id = source.id
    permission.resource_type = Permission.SOURCE
    session.add(permission)
    session.commit()
    for entity in BA_FIXTURES['entities']:
        config.entities.save(entity['$schema'], entity, source_id=source.id)
    get_loom_indexer().index(source=BA_SOURCE)
示例#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 load_ba_fixtures(config):
    # This is messy. Would be cool to do it more cleanly, but how?
    if not len(BA_FIXTURES['entities']):
        with open(os.path.join(FIXTURES, 'ba.mapping.yaml'), 'rb') as fh:
            mapping = yaml.load(fh)
        mapper = Mapper(mapping, config.resolver, scope=config.base_uri)
        with open(os.path.join(FIXTURES, 'ba.csv'), 'rb') as csvfh:
            reader = unicodecsv.DictReader(csvfh)
            for row in reader:
                _, data = mapper.apply(row)
                BA_FIXTURES['entities'].append(data)

    source = Source.ensure({
        'slug': BA_SOURCE,
        'title': 'BiH Parliament',
        'url': 'http://foo.ba/'
    })
    permission = Permission()
    permission.role_id = Role.SYSTEM_USER
    permission.read = True
    permission.write = False
    permission.resource_id = source.id
    permission.resource_type = Permission.SOURCE
    session.add(permission)
    session.commit()
    for entity in BA_FIXTURES['entities']:
        config.entities.save(entity['$schema'], entity, source_id=source.id)
    get_loom_indexer().index(source=BA_SOURCE)
示例#4
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)
示例#5
0
def collection_entity_remove(collection):
    collection = get_collection(collection, authz.WRITE)
    subject = request.args.get('subject')
    if subject is None:
        raise BadRequest()
    collection_remove_entity(collection, subject)
    get_loom_indexer().index_one(subject)
    return jsonify({'status': 'ok'}, status=204)
示例#6
0
def collection_entity_remove(collection):
    collection = get_collection(collection, authz.WRITE)
    subject = request.args.get('subject')
    if subject is None:
        raise BadRequest()
    collection_remove_entity(collection, subject)
    get_loom_indexer().index_one(subject)
    return jsonify({
        'status': 'ok'
    }, status=204)
示例#7
0
 def setUp(self):
     Role.create_defaults()
     self.config = self.app.loom_config
     if not BA_FIXTURES['resolver']:
         schema_dir = os.path.join(FIXTURES, 'schema')
         load_local_schema(self.config.resolver, schema_dir=schema_dir)
         BA_FIXTURES['resolver'] = self.config.resolver
     self.config._resolver = BA_FIXTURES['resolver']
     self.es = get_es()
     get_loom_indexer().configure()
示例#8
0
 def setUp(self):
     Role.create_defaults()
     self.config = self.app.loom_config
     if not BA_FIXTURES['resolver']:
         schema_dir = os.path.join(FIXTURES, 'schema')
         load_local_schema(self.config.resolver, schema_dir=schema_dir)
         BA_FIXTURES['resolver'] = self.config.resolver
     self.config._resolver = BA_FIXTURES['resolver']
     self.es = get_es()
     get_loom_indexer().configure()
示例#9
0
def init():
    "Initialize all parts of the system"
    indexer = get_loom_indexer()
    indexer.configure()
    Role.create_defaults()
    session.commit()
示例#10
0
文件: cli.py 项目: occrp/spindle
def init():
    "Initialize all parts of the system"
    indexer = get_loom_indexer()
    indexer.configure()
    Role.create_defaults()
    session.commit()