Exemple #1
0
def user_index(id):
    require.user_id(id)

    q = Entity.all().filter(Entity.user_id == id)
    if 'category' in request.args:
        q = q.filter(Entity.category == request.args.get('category'))
    all_entities = [{"term": {"entities": e.id}} for e in q]

    esq = {
        "query": {
            "filtered": {
                "query": {"match_all": {}}, "filter": {}
            }
        },
        "size": 0,
        "facets": {
            "entities": {
                "terms": {"field": "entities"}
            },
            "global": {
                "terms": {"field": "entities"},
                "global": True,
                "facet_filter": {"or": all_entities}
            }
        }
    }

    filters = request.args.getlist('entity')
    if len(filters):
        esq['query']['filtered']['filter']['and'] = []
        for entity_id in filters:
            fq = {"term": {"entities": entity_id}}
            esq['query']['filtered']['filter']['and'].append(fq)
    else:
        esq['query']['filtered']['filter']['or'] = all_entities

    res = elastic.search_raw(esq, elastic_index, 'frame')
    filtered_counts = res['facets']['entities']['terms']
    filtered_counts = dict([(int(c['term']), c['count']) for c in filtered_counts])
    total_counts = res['facets']['global']['terms']
    total_counts = dict([(int(c['term']), c['count']) for c in total_counts])

    q = Entity.all().filter(Entity.user_id == id)
    if 'category' in request.args:
        q = q.filter(Entity.category == request.args.get('category'))

    def transform_result(entity):
        data = entity.to_ref()
        data['filtered_count'] = filtered_counts.get(entity.id, 0)
        data['total_count'] = total_counts.get(entity.id, 0)
        return data

    return query_pager(q, 'entities.user_index', transform=transform_result, id=id)
Exemple #2
0
def user_index(id):
    require.user_id(id)

    q = Entity.all().filter(Entity.user_id == id)
    if "category" in request.args:
        q = q.filter(Entity.category == request.args.get("category"))
    all_entities = [{"term": {"entities": e.id}} for e in q]

    esq = {
        "query": {"filtered": {"query": {"match_all": {}}, "filter": {}}},
        "size": 0,
        "facets": {
            "entities": {"terms": {"field": "entities"}},
            "global": {"terms": {"field": "entities"}, "global": True, "facet_filter": {"or": all_entities}},
        },
    }

    filters = request.args.getlist("entity")
    if len(filters):
        esq["query"]["filtered"]["filter"]["and"] = []
        for entity_id in filters:
            fq = {"term": {"entities": entity_id}}
            esq["query"]["filtered"]["filter"]["and"].append(fq)
    else:
        esq["query"]["filtered"]["filter"]["or"] = all_entities

    res = elastic.search_raw(esq, elastic_index, "frame")
    filtered_counts = res["facets"]["entities"]["terms"]
    filtered_counts = dict([(int(c["term"]), c["count"]) for c in filtered_counts])
    total_counts = res["facets"]["global"]["terms"]
    total_counts = dict([(int(c["term"]), c["count"]) for c in total_counts])

    q = Entity.all().filter(Entity.user_id == id)
    if "category" in request.args:
        q = q.filter(Entity.category == request.args.get("category"))

    def transform_result(entity):
        data = entity.to_ref()
        data["filtered_count"] = filtered_counts.get(entity.id, 0)
        data["total_count"] = total_counts.get(entity.id, 0)
        return data

    return query_pager(q, "entities.user_index", transform=transform_result, id=id)
Exemple #3
0
def user_index(id):
    require.user_id(id)

    esq = {
        "query": {
            "filtered": {
                "query": {"match_all": {}}, "filter": {}
            }
        },
        "sort": [{"action_at": {"order": "desc"}}],
        "size": get_limit(),
        "from": get_offset(),
        "facets": {"entities": {
            "terms": {"field": "entities"}}
        }
    }

    filters = request.args.getlist('entity')
    if len(filters):
        esq['query']['filtered']['filter']['and'] = []
        for entity_id in filters:
            fq = {"term": {"entities": entity_id}}
            esq['query']['filtered']['filter']['and'].append(fq)
    else:
        esq['query']['filtered']['filter']['or'] = []
        for entity in Entity.all().filter(Entity.user_id == id):
            fq = {"term": {"entities": entity.id}}
            esq['query']['filtered']['filter']['or'].append(fq)

    res = elastic.search_raw(esq, elastic_index, 'frame')
    frame_urns = [r['_id'] for r in res['hits']['hits']]
    q = Frame.all().filter(Frame.urn.in_(frame_urns))
    frames = dict([(f.urn, f) for f in q])
    frames = [frames.get(urn) for urn in frame_urns]
    return query_pager(frames, 'frames.user_index',
                       count=res['hits']['total'],
                       paginate=False,
                       id=id)
Exemple #4
0
def index():
    q = User.all()
    return query_pager(q, 'users.index')
Exemple #5
0
def index():
    q = Service.all()
    return query_pager(q, 'services.index')
Exemple #6
0
def index():
    q = Frame.all()
    q = q.order_by(Frame.action_at.desc())
    return query_pager(q, 'frames.index')