def index(): # allow to filter for writeable collections only, needed # in some UI scenarios: state = QueryState(request.args, request.authz) permission = request.args.get('permission') if permission not in [request.authz.READ, request.authz.WRITE]: permission = request.authz.READ collections = request.authz.collections[permission] # Other filters for navigation label = request.args.get('label') managed = state.getbool('managed', None) # Include counts (of entities, documents) in list view? counts = state.getbool('counts', False) def converter(colls): return [c.to_dict(counts=counts) for c in colls] facet = [f.lower().strip() for f in request.args.getlist('facet')] q = Collection.find(label=label, countries=state.getfilter('countries'), category=state.getfilter('category'), collection_id=collections, managed=managed) data = Pager(q).to_dict(results_converter=converter) facets = {} if 'countries' in facet: facets['countries'] = { 'values': Collection.facet_by(q, Collection.countries, mapping=COUNTRY_NAMES) } if 'category' in facet: mapping = get_config('COLLECTION_CATEGORIES', {}) facets['category'] = { 'values': Collection.facet_by(q, Collection.category, mapping=mapping) } data['facets'] = facets return jsonify(data)
def index(): enable_cache(vary_user=True) state = QueryState(request.args, request.authz) doc_counts = state.getbool('doc_counts') res = entities_query(state, doc_counts=doc_counts) return jsonify(res)