Пример #1
0
def view(id, slug=None):
    entity = Entity.by_id(id)
    if entity is None:
        raise NotFound()
    if entity.same_as is not None:
        canonical = Entity.by_id(entity.same_as)
        return redirect(entity_link(canonical))
    inbound_sections = []
    slug = url_slug(entity['name'].value)
    for schema in entity.inbound_schemata:
        pager_name = schema.name + '_in'
        pager = Pager(entity.inbound_by_schema(schema), pager_name, id=id, slug=slug, limit=15)
        inbound_sections.append((schema, pager))
    outbound_sections = []
    for schema in entity.outbound_schemata:
        pager_name = schema.name + '_out'
        pager = Pager(entity.outbound_by_schema(schema), pager_name, id=id, slug=slug, limit=15)
        outbound_sections.append((schema, pager))

    canonical_url = entity_link(entity, **dict(request.args.items()))
    entity_hairball = app.config.get('ENTITY_HAIRBALL', True)
    return render_template('entity.html', entity=entity,
        canonical_url=canonical_url,
        entity_hairball=entity_hairball,
        inbound_sections=inbound_sections,
        outbound_sections=outbound_sections,
        render_relation=render_relation)
Пример #2
0
def search():
    searcher = ESSearcher(request.args)
    pager = Pager(searcher)
    conv = lambda c: [x for x in c]
    data = pager.to_dict(results_converter=conv)
    data['facets'] = searcher.facets()
    return jsonify(data)
Пример #3
0
def suggest():
    if not 'q' in request.args or not len(request.args.get('q').strip()):
        raise BadRequest("Missing the query ('q' parameter).")

    q = db.session.query(EntityProperty)
    q = q.filter(EntityProperty.name=='name')
    q = q.filter(EntityProperty.active==True)
    q = q.filter(EntityProperty.entity_id!=None)
    q = q.filter(EntityProperty.value.ilike(request.args.get('q') + '%'))
    if 'project' in request.args:
        q = q.join(Entity)
        q = q.join(Project)
        q = q.filter(Project.slug==request.args.get('project'))
    pager = Pager(q)

    data = []
    def convert(props):
        for prop in props:
            data.append({
                'name': prop.value,
                'api_url': url_for('entities_api.view', id=prop.entity_id)
            })
        return data

    validate_cache(keys='#'.join([d['name'] for d in data]))
    return jsonify(pager.to_dict(results_converter=convert))
Пример #4
0
def suggest():
    if not 'q' in request.args or not len(request.args.get('q').strip()):
        raise BadRequest("Missing the query ('q' parameter).")

    q = db.session.query(EntityProperty)
    q = q.join(Entity)
    q = q.join(Project)
    q = q.outerjoin(Permission)
    q = q.filter(or_(Project.private==False,
        and_(Permission.reader==True, Permission.account==request.account)))
    
    q = q.filter(EntityProperty.name=='name')
    q = q.filter(EntityProperty.active==True)
    q = q.filter(EntityProperty.entity_id!=None)
    q = q.filter(EntityProperty.value_string.ilike(request.args.get('q') + '%'))
    if 'project' in request.args:
        q = q.filter(Project.slug==request.args.get('project'))
    pager = Pager(q)

    data = []
    def convert(props):
        for prop in props:
            data.append({
                'name': prop.value,
                'api_url': url_for('entities_api.view', id=prop.entity_id)
            })
        return data

    validate_cache(keys='#'.join([d['name'] for d in data]))
    return jsonify(pager.to_dict(results_converter=convert))
Пример #5
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_manage(project))
    query = Permission.all()
    query = query.filter_by(project=project)
    pager = Pager(query)
    conv = lambda es: [permissions.to_rest_index(e) for e in es]
    return jsonify(pager.to_dict(conv))
Пример #6
0
def index():
    q = Project.all()
    q = q.outerjoin(Permission)
    q = q.filter(or_(Project.private==False,
        and_(Permission.reader==True, Permission.account==request.account)))
    pager = Pager(q)
    conv = lambda es: [projects.to_rest_index_stats(e) for e in es]
    return jsonify(pager.to_dict(conv))
Пример #7
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_manage(project))
    query = Permission.all()
    query = query.filter_by(project=project)
    pager = Pager(query, slug=slug)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #8
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_manage(project))
    query = Permission.all()
    query = query.filter_by(project=project)
    pager = Pager(query, slug=slug)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #9
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    validate_cache(last_modified=project.updated_at)
    query = Schema.all()
    query = query.filter_by(project=project)
    pager = Pager(query)
    conv = lambda es: [schemata.to_rest_index(e) for e in es]
    return jsonify(pager.to_dict(conv))
Пример #10
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    validate_cache(last_modified=project.updated_at)
    query = Schema.all()
    query = query.filter_by(project=project)
    pager = Pager(query)
    conv = lambda es: [schemata.to_rest_index(e) for e in es]
    return jsonify(pager.to_dict(conv))
Пример #11
0
def index():
    q = Project.all()
    q = q.outerjoin(Permission)
    q = q.filter(or_(Project.private==False,
        and_(Permission.reader==True, Permission.account==request.account)))
    q = q.distinct()
    pager = Pager(q)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #12
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))
    validate_cache(last_modified=project.updated_at)
    query = Schema.all()
    query = query.filter_by(project=project)
    pager = Pager(query, slug=slug)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=not arg_bool('full'))
Пример #13
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))
    validate_cache(last_modified=project.updated_at)
    query = Schema.all()
    query = query.filter_by(project=project)
    pager = Pager(query, slug=slug)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=not arg_bool('full'))
Пример #14
0
def index():
    alias = aliased(Relation)
    q = db.session.query(alias)
    query = filters.for_relations(q, alias)
    query = query.distinct()
    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    result = pager.to_dict()
    result['facets'] = facets.for_relations()
    return jsonify(result, index=True)
Пример #15
0
def index():
    alias = aliased(Entity)
    q = db.session.query(alias)
    query = filters.for_entities(q, alias)
    query = query.distinct()
    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    result = pager.to_dict()
    result['facets'] = facets.for_entities()
    return jsonify(result, index=True)
Пример #16
0
def search():
    # TODO: move to be project-specific, the implement access control!
    searcher = ESSearcher(request.args)
    if 'project' in request.args:
        searcher.add_filter('project.slug', request.args.get('project'))
    pager = Pager(searcher)
    # TODO: get all entities at once:
    conv = lambda res: [entities.to_rest_index(Entity.by_id(r.get('id'))) for r in res]
    data = pager.to_dict(results_converter=conv)
    data['facets'] = searcher.facets()
    return jsonify(data)
Пример #17
0
def index():
    query = filter_query(Entity, Entity.all(), request.args)

    for schema in request.args.getlist('schema'):
        alias = aliased(Schema)
        query = query.join(alias, Entity.schemata)
        query = query.filter(alias.name.in_(schema.split(',')))

    pager = Pager(query)
    conv = lambda es: [entities.to_rest_index(e) for e in es]
    return jsonify(pager.to_dict(conv))
Пример #18
0
def index():
    query = filter_query(Entity, Entity.all(), request.args)

    for schema in request.args.getlist('schema'):
        alias = aliased(Schema)
        query = query.join(alias, Entity.schemata)
        query = query.filter(alias.name.in_(schema.split(',')))

    pager = Pager(query)
    conv = lambda es: [entities.to_rest_index(e) for e in es]
    return jsonify(pager.to_dict(conv))
Пример #19
0
def index():
    q = Project.all()
    q = q.outerjoin(Permission)
    q = q.filter(
        or_(
            Project.private == False,
            and_(Permission.reader == True,
                 Permission.account == request.account)))
    q = q.distinct()
    pager = Pager(q)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #20
0
def _index(query, obj):
    authz.require(authz.project_read(obj.project))
    active_only = arg_bool('active', default=True)
    if active_only:
        query = query.filter_by(active=True)

    if 'name' in request.args:
        query = query.filter_by(name=request.args.get('name'))

    query = query.order_by(Property.created_at.desc())
    pager = Pager(query, obj_id=obj.id)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=False)
Пример #21
0
def index(pipeline_id):
    pipeline = object_or_404(Pipeline.by_id(pipeline_id))
    authz.require(authz.project_read(pipeline.project))

    query = LogEntry.all()
    query = query.filter(LogEntry.pipeline==pipeline)

    if request.args.get('level'):
        query = query.filter(LogEntry.level==request.args.get('level'))

    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #22
0
def index():
    query = File.all()
    query = query.join(Project)
    query = query.outerjoin(Permission)
    query = query.filter(or_(Project.private == False,
        and_(Permission.reader == True, Permission.account==request.account)))

    if request.args.get('project'):
        query = query.filter(Project.slug == request.args.get('project'))

    query = query.distinct()
    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #23
0
def suggest():
    authz.require(authz.logged_in())
    query = request.args.get("q", "") + "%"
    q = db.session.query(Account)
    q = q.filter(or_(Account.full_name.ilike(query), Account.login.ilike(query), Account.email.ilike(query)))
    pager = Pager(q)

    def convert(accounts):
        data = []
        for account in accounts:
            data.append({"display_name": account.display_name, "id": account.id})
        return data

    validate_cache(keys="#".join([d.display_name for d in pager]))
    return jsonify(pager.to_dict(results_converter=convert))
Пример #24
0
def search():
    searcher = Searcher(request.args)
    if 'project' in request.args:
        searcher.add_filter('project.slug', request.args.get('project'))
    pager = Pager(searcher)
    
    def convert(serp):
        ents = Entity.by_id_many([r['id'] for r in serp], request.account)
        results = [ents.get(r['id']) for r in serp]
        results = [entities.to_rest_index(r) for r in results]
        return results

    data = pager.to_dict(results_converter=convert)
    data['facets'] = searcher.facets()
    return jsonify(data)
Пример #25
0
def index():
    query = File.all()
    query = query.join(Project)
    query = query.outerjoin(Permission)
    query = query.filter(
        or_(
            Project.private == False,
            and_(Permission.reader == True,
                 Permission.account == request.account)))

    if request.args.get('project'):
        query = query.filter(Project.slug == request.args.get('project'))

    query = query.distinct()
    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #26
0
def index():
    query = filter_query(Relation, Relation.all(), request.args)

    if request.args.get('source'):
        query = query.filter(Relation.source_id==request.args.getlist('source')[0])

    if request.args.get('target'):
        query = query.filter(Relation.target_id==request.args.getlist('target')[0])
    
    if request.args.get('schema'):
        schemata = request.args.get('schema').split(',')
        query = query.join(Schema)
        query = query.filter(Schema.name.in_(schemata))

    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #27
0
def index():
    query = filter_query(Relation, Relation.all(), request.args)

    if request.args.get('source'):
        query = query.filter(Relation.source_id==request.args.getlist('source')[0])

    if request.args.get('target'):
        query = query.filter(Relation.target_id==request.args.getlist('target')[0])
    
    if request.args.get('schema'):
        schemata = request.args.get('schema').split(',')
        query = query.join(Schema)
        query = query.filter(Schema.name.in_(schemata))

    pager = Pager(query)
    conv = lambda es: [relations.to_rest_index(e) for e in es]
    return jsonify(pager.to_dict(conv))
Пример #28
0
def search():
    searcher = Searcher(request.args)
    searcher.add_facet('schemata.name', 20)
    pager = Pager(searcher, 'search')
    #list(pager)
    schemata_facet = facet_schema_list(Entity, searcher.get_facet('schemata.name'))
    relschema_facet = facet_schema_list(Relation, searcher.get_facet('relations.schema.name'))
    return render_template('search.html', searcher=searcher,
        pager=pager, schemata_facet=schemata_facet, relschema_facet=relschema_facet)
Пример #29
0
def index():
    query = filter_query(Relation, Relation.all(), request.args)

    if request.args.get('source'):
        query = query.filter(
            Relation.source_id == request.args.getlist('source')[0])

    if request.args.get('target'):
        query = query.filter(
            Relation.target_id == request.args.getlist('target')[0])

    if request.args.get('schema'):
        schemata = request.args.get('schema').split(',')
        query = query.join(Schema)
        query = query.filter(Schema.name.in_(schemata))

    pager = Pager(query)
    conv = lambda es: [relations.to_rest_index(e) for e in es]
    return jsonify(pager.to_dict(conv))
Пример #30
0
def suggest():
    authz.require(authz.logged_in())
    query = request.args.get('q', '') + '%'
    q = db.session.query(Account)
    q = q.filter(
        or_(Account.full_name.ilike(query), Account.login.ilike(query),
            Account.email.ilike(query)))
    pager = Pager(q)

    def convert(accounts):
        data = []
        for account in accounts:
            data.append({
                'display_name': account.display_name,
                'id': account.id
            })
        return data

    validate_cache(keys='#'.join([d.display_name for d in pager]))
    return jsonify(pager.to_dict(results_converter=convert))
Пример #31
0
def index():
    query = Pipeline.all()
    query = query.join(Project)
    query = query.outerjoin(Permission)
    query = query.filter(
        or_(Project.private == False, and_(Permission.reader == True, Permission.account == request.account))
    )

    if request.args.get("project"):
        query = query.filter(Project.slug == request.args.get("project"))

    if request.args.get("operation"):
        query = query.filter(Pipeline.operation == request.args.get("operation"))

    query = query.order_by(Pipeline.updated_at.desc())
    query = query.distinct()

    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #32
0
def index():
    query = filter_query(Entity, Entity.all(), request.args)

    if 'q' in request.args and len(request.args.get('q').strip()):
        q = '%%%s%%' % request.args.get('q').strip()
        query = query.join(EntityProperty)
        query = query.filter(EntityProperty.name=='name')
        query = query.filter(EntityProperty.value_string.ilike(q))

    for schema in request.args.getlist('schema'):
        if not len(schema.strip()):
            continue
        alias = aliased(Schema)
        query = query.join(alias, Entity.schemata)
        query = query.filter(alias.name.in_(schema.split(',')))

    query = query.filter(Entity.same_as==None)
    query = query.distinct()
    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Пример #33
0
def make_facets(parent_alias, filter_func, parser_func):
    """ Return a set of facets based on the current query string. This
    will also consider filters set for the query, i.e. only show facets
    that match the current set of filters. """
    facets = {}
    for facet in request.args.getlist('facet'):
        parent_obj = parent_alias()
        q = db.session.query()
        facet_count = func.count(func.distinct(parent_obj.id))
        q = q.add_columns(facet_count)
        q = q.order_by(facet_count.desc())
        q = filter_func(q, parent_obj)
        q = parser_func(parent_obj, facet, facet, q)
        facets[facet] = Pager(q, name='facet_%s' % facet,
                              results_converter=results_process)
    return facets
Пример #34
0
def index():
    query = Project.all()
    pager = Pager(query)
    conv = lambda es: [projects.to_rest_index_stats(e) for e in es]
    return jsonify(pager.to_dict(conv))