当前位置: 首页>>代码示例>>Python>>正文


Python Entity.by_id方法代码示例

本文整理汇总了Python中grano.model.Entity.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Entity.by_id方法的具体用法?Python Entity.by_id怎么用?Python Entity.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grano.model.Entity的用法示例。


在下文中一共展示了Entity.by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: view

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
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)
开发者ID:IuliiSe,项目名称:openinterests.eu,代码行数:29,代码来源:entities.py

示例2: decode

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
 def decode(self, node, cstruct):
     if isinstance(cstruct, Entity):
         if cstruct.project == self.project:
             return cstruct
     if isinstance(cstruct, basestring):
         entity = Entity.by_id(cstruct)
         if entity.project == self.project:
             return entity
     if isinstance(cstruct, dict):
         if cstruct.get('id'):
             entity = Entity.by_id(cstruct.get('id'))
             if entity.project == self.project:
                 return entity
     return None
开发者ID:eocaollai,项目名称:grano,代码行数:16,代码来源:references.py

示例3: update

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def update(id):
    entity = object_or_404(Entity.by_id(id))
    authz.require(authz.project_edit(entity.project))
    data = request_data({'author': request.account})
    entity = entities.save(data, entity=entity)
    db.session.commit()
    return jsonify(entities.to_rest(entity))
开发者ID:nimblemachine,项目名称:grano,代码行数:9,代码来源:entities_api.py

示例4: graph

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def graph(id):
    entity = object_or_404(Entity.by_id(id))
    extractor = GraphExtractor(root_id=entity.id)
    validate_cache(keys=extractor.to_hash())
    if extractor.format == 'gexf':
        return Response(extractor.to_gexf(),
                mimetype='text/xml')
    return jsonify(extractor.to_dict())
开发者ID:eocaollai,项目名称:grano,代码行数:10,代码来源:entities_api.py

示例5: index_single

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def index_single(entity_id):
    """ Index a single entity. """
    entity = Entity.by_id(entity_id)
    if entity.same_as is not None:
        return
    log.debug("Indexing: %s", entity['name'].value)
    body = entities.to_index(entity)
    es.index(index=es_index, doc_type='entity', id=body.pop('id'), body=body)
开发者ID:nimblemachine,项目名称:grano,代码行数:10,代码来源:indexer.py

示例6: entity_changed

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
 def entity_changed(self, entity_id, operation):
     if operation == 'delete':
         es.delete(index=es_index, doc_type='entity', id=entity_id)
     else:
         entity = Entity.by_id(entity_id)
         if entity is None:
             return
         self.index_entity(entity)
         es.indices.refresh(index=es_index)
开发者ID:c0ns0le,项目名称:grano-elasticsearch,代码行数:11,代码来源:indexer.py

示例7: search

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
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)
开发者ID:nimblemachine,项目名称:grano,代码行数:13,代码来源:entities_api.py

示例8: graph

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def graph(id):
    entity = object_or_404(Entity.by_id(id))
    authz.require(authz.entity_read(entity))
    entity_properties = request.args.getlist('entity_property')
    extractor = GraphExtractor(root_id=entity.id,
                               entity_properties=entity_properties)
    validate_cache(keys=extractor.to_hash())
    if extractor.format == 'gexf':
        return Response(extractor.to_gexf(),
                        mimetype='text/xml')
    return jsonify(extractor)
开发者ID:jacqui,项目名称:grano,代码行数:13,代码来源:entities_api.py

示例9: merge

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def merge(orig, dest):
    """ Copy all properties and relations from one entity onto another, then
    mark the source entity as an ID alias for the destionation entity. """
    if orig.id == dest.id:
        return orig

    if dest.same_as == orig.id:
        return orig
    
    if orig.same_as == dest.id:
        return dest

    if dest.same_as is not None:
        # potential infinite recursion here.
        resolved_dest = Entity.by_id(dest.same_as)
        if resolved_dest is not None:
            return merge(orig, resolved_dest)
    
    schemata, seen_schemata = list(), set()
    for schema in dest.schemata + orig.schemata:
        if schema.id in seen_schemata:
            continue
        seen_schemata.add(schema.id)
        schemata.append(schema)

    dest.schemata = schemata

    dest_active = [p.name for p in dest.active_properties]
    for prop in orig.properties:
        if prop.name in dest_active:
            prop.active = False
        prop.entity = dest
    
    for rel in orig.inbound:
        rel.target = dest
    
    for rel in orig.outbound:
        rel.source = dest
    
    orig.same_as = dest.id
    dest.same_as = None
    db.session.flush()
    _entity_changed.delay(dest.id, 'update')
    _entity_changed.delay(orig.id, 'delete')
    return dest
开发者ID:scott2b,项目名称:grano,代码行数:47,代码来源:entities.py

示例10: merge

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def merge(source, dest):
    """ Copy all properties and relations from one entity onto another, then
    mark the source entity as an ID alias for the destionation entity. """
    if source.id == dest.id:
        return source

    if dest.same_as == source.id:
        return source

    if source.same_as == dest.id:
        return dest

    if dest.same_as is not None:
        # potential infinite recursion here.
        canonical = Entity.by_id(dest.same_as)
        if canonical is not None:
            return merge(source, canonical)

    source_schema = source.schema
    if dest.schema.is_parent(source_schema):
        dest.schema = source_schema
    else:
        source_schema = dest.schema.common_parent(source_schema)

    source_valid = [a.name for a in source_schema.attributes]
    dest_active = [p.name for p in dest.active_properties]
    for prop in source.properties:
        if prop.name in source_valid:
            if prop.name in dest_active:
                prop.active = False
            prop.entity = dest
        else:
            properties_logic.delete(prop)

    for rel in source.inbound:
        rel.target = dest

    for rel in source.outbound:
        rel.source = dest

    source.same_as = dest.id
    db.session.flush()
    _entity_changed.delay(dest.id, 'update')
    _entity_changed.delay(source.id, 'delete')
    return dest
开发者ID:Flowdeeps,项目名称:grano,代码行数:47,代码来源:entities.py

示例11: view

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def view(id):
    entity = object_or_404(Entity.by_id(id))
    authz.require(authz.project_read(entity.project))
    return jsonify(entities.to_rest(entity))
开发者ID:nimblemachine,项目名称:grano,代码行数:6,代码来源:entities_api.py

示例12: delete

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def delete(id):
    entity = object_or_404(Entity.by_id(id))
    authz.require(authz.project_edit(entity.project))
    entities.delete(entity)
    db.session.commit()
    raise Gone()
开发者ID:nimblemachine,项目名称:grano,代码行数:8,代码来源:entities_api.py

示例13: entities_index

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def entities_index(obj_id):
    query = Property.all()
    query = query.filter(Property.relation_id != None)
    obj = Entity.by_id(obj_id)
    query = query.filter_by(entity_id=obj_id)
    return _index(query, obj)
开发者ID:gabelula,项目名称:grano,代码行数:8,代码来源:properties_api.py

示例14: view

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def view(id):
    entity = object_or_404(Entity.by_id(id))
    authz.require(authz.entity_read(entity))
    return jsonify(entity)
开发者ID:jacqui,项目名称:grano,代码行数:6,代码来源:entities_api.py

示例15: entities_index

# 需要导入模块: from grano.model import Entity [as 别名]
# 或者: from grano.model.Entity import by_id [as 别名]
def entities_index(obj_id):
    query = EntityProperty.all()
    obj = Entity.by_id(obj_id)
    query = query.filter_by(entity_id=obj_id)
    return _index(query, obj)
开发者ID:ahurriyetoglu,项目名称:grano,代码行数:7,代码来源:properties_api.py


注:本文中的grano.model.Entity.by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。