Example #1
0
def view(id):
    authz.require(authz.system_edit())
    pairing = obj_or_404(Pairing.by_id(id))
    return jsonify(
        {
            "status": "ok",
            "left": EntityQuery.by_id(pairing.left_id),
            "right": EntityQuery.by_id(pairing.right_id),
            "pairing": pairing,
        }
    )
Example #2
0
def update(id):
    authz.require(authz.system_edit())
    entity = obj_or_404(EntityQuery.by_id(id))
    context = Context.create(current_user, {})
    entity.update(request_data(), context)
    db.session.commit()
    return redirect(url_for(".view", id=entity.id))
Example #3
0
 def deserialize(self, value):
     from nomenklatura.model.entity import Entity
     from nomenklatura.query import EntityQuery
     if isinstance(value, Entity):
         return value
     ent = EntityQuery.by_id(value)
     # if ent is None:
     #    raise TypeError("Entity does not exist: %r" % value)
     return ent
Example #4
0
def load_entity(context, mapping, record):
    type_ = types.get(mapping.get('type'))
    if type_ is None:
        log.warning("No type defined for entity in mapping: %r", mapping)
        return

    query = {'assume': [context.id], 'type': unicode(type_)}
    has_key = False

    data = [(types.Object.attributes.type, type_)]
    for attr in type_.attributes:
        if attr.name not in mapping or attr == types.Object.attributes.type:
            continue
        attr_map = mapping[attr.name]
        if attr.data_type == 'entity':
            value = load_entity(context, attr_map, record)
        else:
            value = record.get(attr_map.get('field'))

        if attr_map.get('key'):
            has_key = True
            query[attr.name] = value

        data.append((attr, value))

    query = EntityQuery(query)
    entity = query.first() if has_key else None
    if entity is None:
        entity = Entity()

    for (attr, value) in data:
        entity.set(attr, value, context)

    db.session.commit()
    # log.info("Loaded entity: %r", entity)
    return entity
Example #5
0
def enrich_entity(root, entity_id, spider=None):
    entity = EntityQuery.by_id(entity_id)
    if entity is None:
        log.error('Entity does not exist: %s', entity_id)
        return

    for name, cls in get_spiders().items():
        if spider is not None and spider != name:
            continue

        try:
            inst = cls()
            inst.lookup(root, entity)
            db.session.commit()
        except Exception, e:
            log.exception(e)
            db.session.rollback()
Example #6
0
def view(id):
    authz.require(authz.system_read())
    entity = obj_or_404(EntityQuery.by_id(id))
    return jsonify(entity)