コード例 #1
0
ファイル: entity.py プロジェクト: OpenRefine/nomenklatura
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
ファイル: entity.py プロジェクト: OpenRefine/nomenklatura
def update(dataset, entity):
    dataset = Dataset.find(dataset)
    authz.require(authz.dataset_edit(dataset))
    entity = Entity.find(dataset, entity)
    data = request_content()
    try:
        entity.update(data, request.account)
        db.session.commit()
        flash("Updated %s" % entity.display_name, 'success')
        return redirect(url_for('.view', dataset=dataset.name, entity=entity.id))
    except Invalid, inv:
        return handle_invalid(inv, view, data=data,
                              args=[dataset.name, entity.id])
コード例 #3
0
ファイル: entity.py プロジェクト: tmarthal/nomenklatura
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)
コード例 #4
0
ファイル: entity.py プロジェクト: tmarthal/nomenklatura
def update(dataset, entity):
    dataset = Dataset.find(dataset)
    authz.require(authz.dataset_edit(dataset))
    entity = Entity.find(dataset, entity)
    data = request_content()
    try:
        entity.update(data, request.account)
        db.session.commit()
        flash("Updated %s" % entity.display_name, 'success')
        return redirect(
            url_for('.view', dataset=dataset.name, entity=entity.id))
    except Invalid, inv:
        return handle_invalid(inv,
                              view,
                              data=data,
                              args=[dataset.name, entity.id])