本文整理汇总了Python中aleph.model.Collection.all_by_ids方法的典型用法代码示例。如果您正苦于以下问题:Python Collection.all_by_ids方法的具体用法?Python Collection.all_by_ids怎么用?Python Collection.all_by_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aleph.model.Collection
的用法示例。
在下文中一共展示了Collection.all_by_ids方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_collections
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_by_ids [as 别名]
def get_collections(data):
collections = []
for coll_id in data.get('collections'):
if isinstance(coll_id, dict):
coll_id = coll_id.get('id')
collections.append(coll_id)
return Collection.all_by_ids(collections).all()
示例2: peek_query
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_by_ids [as 别名]
def peek_query(args):
if not isinstance(args, MultiDict):
args = MultiDict(args)
text = args.get('q', '').strip()
q = text_query(text)
filters = parse_filters(args)
for entity in args.getlist('entity'):
filters.append(('entities.id', entity))
q = filter_query(q, filters, [])
q = add_filter(q, {
'not': {
'terms': {
'collection_id': authz.collections(authz.READ)
}
}
})
q = {
'query': q,
'size': 0,
'aggregations': {
'collections': {
'terms': {'field': 'collection_id', 'size': 30}
}
},
'_source': False
}
# import json
# print json.dumps(q, indent=2)
result = get_es().search(index=get_es_index(), body=q,
doc_type=TYPE_DOCUMENT)
aggs = result.get('aggregations', {}).get('collections', {})
buckets = aggs.get('buckets', [])
q = Collection.all_by_ids([b['key'] for b in buckets])
q = q.filter(Collection.creator_id != None) # noqa
objs = {o.id: o for o in q.all()}
roles = {}
for bucket in buckets:
collection = objs.get(bucket.get('key'))
if collection is None or collection.private:
continue
if collection.creator_id in roles:
roles[collection.creator_id]['total'] += bucket.get('doc_count')
else:
roles[collection.creator_id] = {
'name': collection.creator.name,
'email': collection.creator.email,
'total': bucket.get('doc_count')
}
roles = sorted(roles.values(), key=lambda r: r['total'], reverse=True)
roles = [format_total(r) for r in roles]
total = result.get('hits', {}).get('total')
return format_total({
'roles': roles,
'active': total > 0,
'total': total
})
示例3: get_collections
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_by_ids [as 别名]
def get_collections(data):
collections = []
collection_id = data.get('collection_id') or []
if not isinstance(collection_id, (list, set, tuple)):
collection_id = [collection_id]
for coll_id in collection_id:
if isinstance(coll_id, dict):
coll_id = coll_id.get('id')
collections.append(coll_id)
return Collection.all_by_ids(collections).all()
示例4: convert_collections
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_by_ids [as 别名]
def convert_collections(facet):
output = {'values': []}
ids = [b.get('key') for b in facet.get('buckets', [])]
if not len(ids):
return output
collections = Collection.all_by_ids(ids).all()
for bucket in facet.get('buckets', []):
key = bucket.get('key')
for collection in collections:
if collection.id != key:
continue
output['values'].append({
'id': key,
'label': collection.label,
'count': bucket.get('doc_count')
})
return output
示例5: convert_collections
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_by_ids [as 别名]
def convert_collections(facet):
results = []
ids = [b.get('key') for b in facet.get('buckets', [])]
if not len(ids):
return {'values': []}
collections = Collection.all_by_ids(ids).all()
for bucket in facet.get('buckets', []):
key = bucket.get('key')
for collection in collections:
if collection.id != key:
continue
results.append({
'id': key,
'label': collection.label,
'category': collection.category,
'count': bucket.get('doc_count')
})
return {'values': results}
示例6: index
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_by_ids [as 别名]
def index():
collections = authz.collections(authz.READ)
enable_cache(vary_user=True, vary=collections)
q = Collection.all_by_ids(collections)
q = q.order_by(Collection.label.asc())
return jsonify(Pager(q))