예제 #1
0
def view(dataset, entity):
    dataset = Dataset.find(dataset)
    entity = Entity.find(dataset, entity)
    print entity.data
    format = response_format()
    if format == 'json':
        return jsonify(entity)
    query = request.args.get('query', '').strip().lower()
    choices = match_op(entity.name, dataset)
    choices = filter(lambda (c,e,s): e != entity.id, choices)
    if len(query):
        choices = filter(lambda (c,e,s): query in Entity.find(dataset,e).name.lower(),
                         choices)
                         # THIS is very inefficient - rather do this
                         # differently
    pager = Pager(choices, '.view', dataset=dataset.name,
                  entity=entity.id, limit=10)

    # HACK: Fetch only the entities on the selected page.
    entities = Entity.id_map(dataset, map(lambda (c,v,s): v,
        pager.query[pager.offset:pager.offset+pager.limit]))
    for i, (c,e,s) in enumerate(pager.query):
        if e in entities:
            pager.query[i] = (c, entities.get(e), s)

    return render_template('entity/view.html', dataset=dataset,
                           entity=entity, entities=pager, query=query)
예제 #2
0
def match(dataset, alias, random=False):
    dataset = Dataset.find(dataset)
    authz.require(authz.dataset_edit(dataset))
    alias = Alias.find(dataset, alias)
    random = random or request.args.get('random')=='True'
    choices = match_op(alias.name, dataset,
            query=request.args.get('query'))
    pager = Pager(choices, '.match',
        dataset=dataset.name, alias=alias.id,
        limit=10)

    # HACK: Fetch only the entities on the selected page.
    entities = Entity.id_map(dataset, map(lambda (c,e,s): e,
        pager.query[pager.offset:pager.offset+pager.limit]))
    for i, (c,e,s) in enumerate(pager.query):
        if e in entities:
            pager.query[i] = (c, entities.get(e), s)

    html = render_template('alias/match.html',
            dataset=dataset, alias=alias, choices=pager,
            random=random)
    choice = 'INVALID' if alias.is_invalid else alias.entity_id
    if len(choices) and choice is None:
        c, e, s = choices[0]
        choice = 'INVALID' if s <= 50 else e.id
    return htmlfill.render(html, force_defaults=False,
            defaults={'choice': choice,
                      'name': alias.name,
                      'query': request.args.get('query', ''),
                      'random': random})
예제 #3
0
파일: value.py 프로젝트: okfn/nomenklatura
def view(dataset, value):
    dataset = Dataset.find(dataset)
    value = Value.find(dataset, value)
    format = response_format()
    if format == 'json':
        return jsonify(value)
    query = request.args.get('query', '').strip().lower()
    choices = match_op(value.value, dataset)
    choices = filter(lambda (c,v,s): v != value.id, choices)
    if len(query):
        choices = filter(lambda (c,v,s): query in Value.find(dataset,v).value.lower(),
                         choices)
                         # THIS is very inefficient - rather do this
                         # differently
    pager = Pager(choices, '.view', dataset=dataset.name,
                  value=value.id, limit=10)

    # HACK: Fetch only the values on the selected page.
    value_objs = Value.id_map(dataset, map(lambda (c,v,s): v,
        pager.query[pager.offset:pager.offset+pager.limit]))
    for i, (c,v,s) in enumerate(pager.query):
        if v in value_objs:
            pager.query[i] = (c, value_objs.get(v), s)

    return render_template('value/view.html', dataset=dataset,
                           value=value, values=pager, query=query)
예제 #4
0
파일: link.py 프로젝트: okfn/nomenklatura
def match(dataset, link, random=False):
    dataset = Dataset.find(dataset)
    authz.require(authz.dataset_edit(dataset))
    link = Link.find(dataset, link)
    random = random or request.args.get('random')=='True'
    choices = match_op(link.key, dataset,
            query=request.args.get('query'))
    pager = Pager(choices, '.match',
        dataset=dataset.name, link=link.id,
        limit=10)

    # HACK: Fetch only the values on the selected page.
    value_objs = Value.id_map(dataset, map(lambda (c,v,s): v,
        pager.query[pager.offset:pager.offset+pager.limit]))
    for i, (c,v,s) in enumerate(pager.query):
        if v in value_objs:
            pager.query[i] = (c, value_objs.get(v), s)

    html = render_template('link/match.html',
            dataset=dataset, link=link, choices=pager,
            random=random)
    choice = 'INVALID' if link.is_invalid else link.value_id
    if len(choices) and choice is None:
        c, v, s = choices[0]
        choice = 'INVALID' if s <= 50 else v
    return htmlfill.render(html, force_defaults=False,
            defaults={'choice': choice,
                      'value': link.key,
                      'query': request.args.get('query', ''),
                      'random': random})
예제 #5
0
def match(dataset, alias, random=False):
    dataset = Dataset.find(dataset)
    authz.require(authz.dataset_edit(dataset))
    alias = Alias.find(dataset, alias)
    random = random or request.args.get('random') == 'True'
    choices = match_op(alias.name, dataset, query=request.args.get('query'))
    pager = Pager(choices,
                  '.match',
                  dataset=dataset.name,
                  alias=alias.id,
                  limit=10)

    # HACK: Fetch only the entities on the selected page.
    entities = Entity.id_map(
        dataset,
        map(lambda (c, e, s): e,
            pager.query[pager.offset:pager.offset + pager.limit]))
    for i, (c, e, s) in enumerate(pager.query):
        if e in entities:
            pager.query[i] = (c, entities.get(e), s)

    html = render_template('alias/match.html',
                           dataset=dataset,
                           alias=alias,
                           choices=pager,
                           random=random)
    choice = 'INVALID' if alias.is_invalid else alias.entity_id
    if len(choices) and choice is None:
        c, e, s = choices[0]
        choice = 'INVALID' if s <= 50 else e.id
    return htmlfill.render(html,
                           force_defaults=False,
                           defaults={
                               'choice': choice,
                               'name': alias.name,
                               'query': request.args.get('query', ''),
                               'random': random
                           })
예제 #6
0
def view(dataset, entity):
    dataset = Dataset.find(dataset)
    entity = Entity.find(dataset, entity)
    print entity.data
    format = response_format()
    if format == 'json':
        return jsonify(entity)
    query = request.args.get('query', '').strip().lower()
    choices = match_op(entity.name, dataset)
    choices = filter(lambda (c, e, s): e != entity.id, choices)
    if len(query):
        choices = filter(
            lambda (c, e, s): query in Entity.find(dataset, e).name.lower(),
            choices)
        # THIS is very inefficient - rather do this
        # differently
    pager = Pager(choices,
                  '.view',
                  dataset=dataset.name,
                  entity=entity.id,
                  limit=10)

    # HACK: Fetch only the entities on the selected page.
    entities = Entity.id_map(
        dataset,
        map(lambda (c, v, s): v,
            pager.query[pager.offset:pager.offset + pager.limit]))
    for i, (c, e, s) in enumerate(pager.query):
        if e in entities:
            pager.query[i] = (c, entities.get(e), s)

    return render_template('entity/view.html',
                           dataset=dataset,
                           entity=entity,
                           entities=pager,
                           query=query)
예제 #7
0
def view(dataset):
    dataset = Dataset.find(dataset)
    format = response_format()
    if format == 'json':
        return jsonify(dataset)
    unmatched = Alias.all_unmatched(dataset).count()
    entities = Entity.all(dataset, query=request.args.get('query'))
    pager = Pager(entities, '.view', dataset=dataset.name, limit=10)
    return render_template('dataset/view.html',
                           entities=pager,
                           num_entities=len(pager),
                           num_aliases=Alias.all(dataset).count(),
                           invalid=Alias.all_invalid(dataset).count(),
                           query=request.args.get('query', ''),
                           dataset=dataset,
                           unmatched=unmatched)