当前位置: 首页>>代码示例>>Python>>正文


Python Collection.by_id方法代码示例

本文整理汇总了Python中aleph.model.Collection.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Collection.by_id方法的具体用法?Python Collection.by_id怎么用?Python Collection.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aleph.model.Collection的用法示例。


在下文中一共展示了Collection.by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def delete(id):
    authz.require(authz.collection_write(id))
    collection = obj_or_404(Collection.by_id(id))
    analyze_terms.delay(collection.terms)
    collection.delete()
    db.session.commit()
    return jsonify({'status': 'ok'})
开发者ID:01-,项目名称:aleph,代码行数:9,代码来源:collections_api.py

示例2: create

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def create(collection_id):
    collection = obj_or_404(Collection.by_id(collection_id))
    authz.require(authz.collection_write(collection.id))
    network = Network.create(request_data(), collection, request.auth_role)
    db.session.commit()
    log_event(request)
    return view(collection_id, network.id)
开发者ID:CodeForAfrica,项目名称:aleph,代码行数:9,代码来源:networks_api.py

示例3: update

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def update(id):
    authz.require(authz.collection_write(id))
    collection = obj_or_404(Collection.by_id(id))
    collection.update(request_data())
    db.session.add(collection)
    db.session.commit()
    return view(id)
开发者ID:backgroundcheck,项目名称:aleph,代码行数:9,代码来源:collections_api.py

示例4: get_results

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def get_results(query, limit):
    collections = {}
    for i, row in enumerate(scan_iter(query)):
        if i >= limit:
            return
        data = {
            'file_url': url_for('documents_api.file',
                                document_id=row.get('_id'))
        }
        for name, value in row.get('_source').items():
            if name == 'collection_id':
                colls = []
                for coll in value:
                    if coll not in collections:
                        source = Collection.by_id(coll)
                        if source is None:
                            collections[coll] = '[Deleted collection %s]' % value
                        else:
                            collections[coll] = source.label
                    colls.append(collections[coll])
                value = ', '.join(sorted(colls))
                name = 'collections'
            if name not in FIELDS:
                continue
            if isinstance(value, (list, tuple, set)):
                value = ', '.join(value)
            data[name] = value
        yield data
开发者ID:adamchainz,项目名称:aleph,代码行数:30,代码来源:exports_api.py

示例5: delete

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def delete(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_write(id))
    delete_collection.apply_async([collection.id], queue=USER_QUEUE,
                                  routing_key=USER_ROUTING_KEY)
    log_event(request)
    return jsonify({'status': 'ok'})
开发者ID:CodeForAfrica,项目名称:aleph,代码行数:9,代码来源:collections_api.py

示例6: ingest_upload

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def ingest_upload(collection_id):
    collection = obj_or_404(Collection.by_id(collection_id))
    authz.require(authz.collection_write(collection.id))
    log_event(request)
    try:
        meta = json.loads(request.form.get('meta', '{}'))
    except Exception as ex:
        raise BadRequest(unicode(ex))

    metas = []
    for storage in request.files.values():
        file_meta = meta.copy()
        file_meta['mime_type'] = storage.mimetype
        file_meta['file_name'] = storage.filename
        validate(file_meta, 'metadata.json#')
        file_meta = Metadata.from_data(file_meta)
        file_meta.crawler_id = 'user_upload:%s' % request.auth_role.id
        file_meta.crawler_run = make_textid()
        sec_fn = os.path.join(get_upload_folder(),
                              secure_filename(storage.filename))
        storage.save(sec_fn)
        ingest_file(collection.id, file_meta, sec_fn, move=True,
                    queue=USER_QUEUE, routing_key=USER_ROUTING_KEY)
        metas.append(file_meta)
    return jsonify({'status': 'ok', 'metadata': metas})
开发者ID:CodeForAfrica,项目名称:aleph,代码行数:27,代码来源:ingest_api.py

示例7: get_collection

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def get_collection(collection_id):
    """Fetch a collection from the index."""
    if collection_id is None:
        return
    key = cache.object_key(Collection, collection_id)
    data = cache.get_complex(key)
    if data is not None:
        return data

    collection = Collection.by_id(collection_id)
    if collection is None:
        return

    data = collection.to_dict()
    stats = get_collection_stats(collection.id)
    data['count'] = stats['count']
    data['schemata'] = stats['schemata']

    # if no countries or langs are given, take the most common from the data.
    countries = ensure_list(collection.countries)
    countries = countries or stats['countries'].keys()
    data['countries'] = registry.country.normalize_set(countries)

    languages = ensure_list(collection.languages)
    languages = languages or stats['languages'].keys()
    data['languages'] = registry.language.normalize_set(languages)
    cache.set_complex(key, data, expire=cache.EXPIRE)
    return data
开发者ID:pudo,项目名称:aleph,代码行数:30,代码来源:collections.py

示例8: update

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def update(collection_id, id):
    collection = obj_or_404(Collection.by_id(collection_id))
    authz.require(authz.collection_write(collection_id))
    network = obj_or_404(Network.by_id_collection(id, collection))
    network.update(request_data())
    log_event(request)
    db.session.commit()
    return view(collection_id, network.id)
开发者ID:CodeForAfrica,项目名称:aleph,代码行数:10,代码来源:networks_api.py

示例9: delete

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def delete(collection_id, id):
    collection = obj_or_404(Collection.by_id(collection_id))
    authz.require(authz.collection_write(collection.id))
    network = obj_or_404(Network.by_id_collection(id, collection))
    network.delete()
    db.session.commit()
    log_event(request)
    return jsonify({'status': 'ok'})
开发者ID:CodeForAfrica,项目名称:aleph,代码行数:10,代码来源:networks_api.py

示例10: test_delete_source

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
 def test_delete_source(self):
     collection = Collection.by_id(1000)
     res = self.client.get('/api/1/query?q="mention fruit"')
     assert res.json['total'] == 1, res.json
     delete_collection(collection.id)
     optimize_search()
     res = self.client.get('/api/1/query?q="mention fruit"')
     assert res.json['total'] == 0, res.json
开发者ID:CodeForAfrica,项目名称:aleph,代码行数:10,代码来源:test_index.py

示例11: delete

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def delete(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_write(id))
    collection.delete()
    for entity in collection.entities:
        update_entity(entity)
    db.session.commit()
    return jsonify({'status': 'ok'})
开发者ID:andkamau,项目名称:aleph,代码行数:10,代码来源:collections_api.py

示例12: delete

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def delete(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_write(id))
    # TODO: race condition-ish...
    for entity in collection.entities:
        analyze_entity.delay(entity.id)
    collection.delete()
    db.session.commit()
    return jsonify({'status': 'ok'})
开发者ID:stefanw,项目名称:aleph,代码行数:11,代码来源:collections_api.py

示例13: pending

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def pending(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_read(id))
    q = collection.pending_entities()
    q = q.limit(30)
    entities = []
    for entity in q.all():
        data = entity.to_dict()
        data['name_latin'] = latinize_text(entity.name, lowercase=False)
        entities.append(data)
    return jsonify({'results': entities, 'total': len(entities)})
开发者ID:rlugojr,项目名称:aleph,代码行数:13,代码来源:collections_api.py

示例14: paths

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
def paths(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_read(collection.id))
    start_entity_id = request.args.get('entity_id')
    labels = request.args.getlist('label')
    types = request.args.getlist('type')
    collection_id = request.args.getlist('collection_id')
    end_collection_id = authz.collections_intersect(authz.READ, collection_id)
    q = Path.find(collection, start_entity_id=start_entity_id, labels=labels,
                  types=types, end_collection_id=end_collection_id)
    data = Pager(q, id=collection.id).to_dict()
    data['facets'] = Path.facets(collection, start_entity_id=start_entity_id,
                                 labels=labels, types=types,
                                 end_collection_id=end_collection_id,
                                 collection_id=authz.collections(authz.READ))
    return jsonify(data)
开发者ID:CodeForAfrica,项目名称:aleph,代码行数:18,代码来源:collections_api.py

示例15: create_document

# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import by_id [as 别名]
 def create_document(self, meta, type=None):
     if meta.content_hash:
         q = Document.all()
         if meta.foreign_id:
             q = q.filter(Document.foreign_id == meta.foreign_id)
         else:
             q = q.filter(Document.content_hash == meta.content_hash)
         clause = Collection.id == self.collection_id
         q = q.filter(Document.collections.any(clause))
         document = q.first()
     if document is None:
         document = Document()
         document.collections = [Collection.by_id(self.collection_id)]
     document.meta = meta
     document.type = type or self.DOCUMENT_TYPE
     db.session.add(document)
     db.session.flush()
     return document
开发者ID:adamchainz,项目名称:aleph,代码行数:20,代码来源:ingestor.py


注:本文中的aleph.model.Collection.by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。