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


Python EntityMapper.get_by_ids方法代码示例

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


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

示例1: move_entities

# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_ids [as 别名]
    def move_entities(old_node, new_type_id, entity_ids):
        root = g.nodes[old_node.root[-1]]
        delete_ids = []
        if new_type_id:  # A new type was selected
            if root.multiple:
                cleaned_entity_ids = []
                for entity in EntityMapper.get_by_ids(entity_ids):
                    if any(node.id == int(new_type_id) for node in entity.nodes):
                        delete_ids.append(entity.id)  # If already linked add to delete ids
                    else:
                        cleaned_entity_ids.append(entity.id)
                entity_ids = cleaned_entity_ids
            if entity_ids:
                sql = """
                    UPDATE model.{table} SET range_id = %(new_type_id)s
                    WHERE range_id = %(old_type_id)s AND domain_id IN %(entity_ids)s;""".format(
                    table='link_property' if root.name in app.config['PROPERTY_TYPES'] else 'link')
                params = {
                    'old_type_id': old_node.id,
                    'new_type_id': new_type_id,
                    'entity_ids': tuple(entity_ids)}
                g.cursor.execute(sql, params)
                debug_model['div sql'] += 1
        else:
            delete_ids = entity_ids  # No new type was selected so delete all links

        if delete_ids:
            sql = """
                DELETE FROM model.{table}
                WHERE range_id = %(old_type_id)s AND domain_id IN %(delete_ids)s;""".format(
                table='link_property' if root.name in app.config['PROPERTY_TYPES'] else 'link')
            g.cursor.execute(sql, {'old_type_id': old_node.id, 'delete_ids': tuple(delete_ids)})
            debug_model['div sql'] += 1
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:35,代码来源:node.py

示例2: get_links

# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_ids [as 别名]
 def get_links(entity, codes, inverse=False):
     from openatlas.models.entity import EntityMapper
     sql = """
         SELECT l.id, l.property_code, l.domain_id, l.range_id, l.description, l.created,
             l.modified, e.name, l.type_id,
             COALESCE(to_char(l.begin_from, 'yyyy-mm-dd BC'), '') AS begin_from, l.begin_comment,
             COALESCE(to_char(l.begin_to, 'yyyy-mm-dd BC'), '') AS begin_to,
             COALESCE(to_char(l.end_from, 'yyyy-mm-dd BC'), '') AS end_from, l.end_comment,
             COALESCE(to_char(l.end_to, 'yyyy-mm-dd BC'), '') AS end_to
         FROM model.link l
         JOIN model.entity e ON l.{second}_id = e.id AND l.property_code IN %(codes)s
         WHERE l.{first}_id = %(entity_id)s GROUP BY l.id, e.name ORDER BY e.name;""".format(
         first='range' if inverse else 'domain', second='domain' if inverse else 'range')
     g.cursor.execute(sql, {
         'entity_id': entity if type(entity) is int else entity.id,
         'codes': tuple(codes if type(codes) is list else [codes])})
     debug_model['link sql'] += 1
     entity_ids = set()
     result = g.cursor.fetchall()
     for row in result:
         entity_ids.add(row.domain_id)
         entity_ids.add(row.range_id)
     entities = {entity.id: entity for entity in EntityMapper.get_by_ids(entity_ids)}
     links = []
     for row in result:
         links.append(Link(row, domain=entities[row.domain_id], range_=entities[row.range_id]))
     return links
开发者ID:craws,项目名称:OpenAtlas,代码行数:29,代码来源:link.py

示例3: source_add2

# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_ids [as 别名]
def source_add2(id_, class_name):
    """ Link an entity to source coming from the source"""
    source = EntityMapper.get_by_id(id_)
    if request.method == 'POST':
        for entity in EntityMapper.get_by_ids(request.form.getlist('values')):
            source.link('P67', entity)
        return redirect(url_for('source_view', id_=source.id) + '#tab-' + class_name)
    form = build_table_form(class_name, source.get_linked_entities('P67'))
    return render_template('source/add2.html', source=source, class_name=class_name, form=form)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:11,代码来源:source.py

示例4: involvement_insert

# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_ids [as 别名]
def involvement_insert(origin_id):
    origin = EntityMapper.get_by_id(origin_id)
    form = build_form(ActorForm, 'Involvement')
    if origin.view_name == 'event':
        del form.event
    else:
        del form.actor
    form.activity.choices = [('P11', g.properties['P11'].name_inverse)]
    if origin.class_.code in ['E7', 'E8', 'E12']:
        form.activity.choices.append(('P14', g.properties['P14'].name_inverse))
    if origin.class_.code == 'E8':
        form.activity.choices.append(('P22', g.properties['P22'].name_inverse))
        form.activity.choices.append(('P23', g.properties['P23'].name_inverse))
    if form.validate_on_submit():
        g.cursor.execute('BEGIN')
        try:
            if origin.view_name == 'event':
                for actor in EntityMapper.get_by_ids(ast.literal_eval(form.actor.data)):
                    link_id = origin.link(form.activity.data, actor, form.description.data)
                    DateMapper.save_link_dates(link_id, form)
                    NodeMapper.save_link_nodes(link_id, form)
            else:
                for event in EntityMapper.get_by_ids(ast.literal_eval(form.event.data)):
                    link_id = event.link(form.activity.data, origin, form.description.data)
                    DateMapper.save_link_dates(link_id, form)
                    NodeMapper.save_link_nodes(link_id, form)
            g.cursor.execute('COMMIT')
            flash(_('entity created'), 'info')
        except Exception as e:  # pragma: no cover
            g.cursor.execute('ROLLBACK')
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        if form.continue_.data == 'yes':
            return redirect(url_for('involvement_insert', origin_id=origin_id))
        tab = 'actor' if origin.view_name == 'event' else 'event'
        return redirect(url_for(origin.view_name + '_view', id_=origin.id) + '#tab-' + tab)
    return render_template('involvement/insert.html', origin=origin, form=form)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:39,代码来源:involvement.py

示例5: get_linked_entities

# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_ids [as 别名]
 def get_linked_entities(entity, codes, inverse=False):
     from openatlas.models.entity import EntityMapper
     sql = """
         SELECT range_id AS result_id FROM model.link
         WHERE domain_id = %(entity_id)s AND property_code IN %(codes)s;"""
     if inverse:
         sql = """
             SELECT domain_id AS result_id FROM model.link
             WHERE range_id = %(entity_id)s AND property_code IN %(codes)s;"""
     g.cursor.execute(sql, {
         'entity_id': entity if type(entity) is int else entity.id,
         'codes': tuple(codes if type(codes) is list else [codes])})
     debug_model['link sql'] += 1
     ids = [element for (element,) in g.cursor.fetchall()]
     return EntityMapper.get_by_ids(ids)
开发者ID:craws,项目名称:OpenAtlas,代码行数:17,代码来源:link.py

示例6: source_add

# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_ids [as 别名]
def source_add(origin_id):
    """ Link an entity to source coming from the entity."""
    origin = EntityMapper.get_by_id(origin_id)
    if request.method == 'POST':
        g.cursor.execute('BEGIN')
        try:
            for entity in EntityMapper.get_by_ids(request.form.getlist('values')):
                entity.link('P67', origin)
            g.cursor.execute('COMMIT')
        except Exception as e:  # pragma: no cover
            g.cursor.execute('ROLLBACK')
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        return redirect(url_for(origin.view_name + '_view', id_=origin.id) + '#tab-source')
    form = build_table_form('source', origin.get_linked_entities('P67', True))
    return render_template('source/add.html', origin=origin, form=form)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:18,代码来源:source.py

示例7: insert

# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_ids [as 别名]
 def insert(entity,
            property_code: str,
            linked_entities,
            description: Optional[str] = None,
            inverse: Optional[bool] = False):
     from openatlas.models.entity import Entity, EntityMapper
     # linked_entities can be an entity, an entity id or a list of them
     if not entity or not linked_entities:  # pragma: no cover
         return
     property_ = g.properties[property_code]
     try:
         linked_entities = ast.literal_eval(linked_entities)
     except (SyntaxError, ValueError):
         pass
     linked_entities = linked_entities if type(linked_entities) is list else [linked_entities]
     if type(linked_entities[0]) is not Entity:
         linked_entities = EntityMapper.get_by_ids(linked_entities)
     result = None
     for linked_entity in linked_entities:
         domain = linked_entity if inverse else entity
         range_ = entity if inverse else linked_entity
         domain_error = True
         range_error = True
         if property_.find_object('domain_class_code', g.classes[domain.class_.code].code):
             domain_error = False
         if property_.find_object('range_class_code', g.classes[range_.class_.code].code):
             range_error = False
         if domain_error or range_error:
             text = _('error link') + ': ' + g.classes[domain.class_.code].code + ' > '
             text += property_code + ' > ' + g.classes[range_.class_.code].code
             logger.log('error', 'model', text)
             flash(text, 'error')
             continue
         sql = """
             INSERT INTO model.link (property_code, domain_id, range_id, description)
             VALUES (%(property_code)s, %(domain_id)s, %(range_id)s, %(description)s)
             RETURNING id;"""
         # Todo: build only one sql and get execution out of loop
         g.cursor.execute(sql, {'property_code': property_code, 'domain_id': domain.id,
                                'range_id': range_.id, 'description': description})
         debug_model['link sql'] += 1
         result = g.cursor.fetchone()[0]
     return result
开发者ID:stefaneichert,项目名称:openAtlas,代码行数:45,代码来源:link.py

示例8: member_insert

# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_ids [as 别名]
def member_insert(origin_id):
    origin = EntityMapper.get_by_id(origin_id)
    form = build_form(MemberForm, 'Member')
    del form.group
    form.origin_id.data = origin.id
    if form.validate_on_submit():
        g.cursor.execute('BEGIN')
        try:
            for actor in EntityMapper.get_by_ids(ast.literal_eval(form.actor.data)):
                link_id = origin.link('P107', actor, form.description.data)
                DateMapper.save_link_dates(link_id, form)
                NodeMapper.save_link_nodes(link_id, form)
            g.cursor.execute('COMMIT')
            flash(_('entity created'), 'info')
        except Exception as e:  # pragma: no cover
            g.cursor.execute('ROLLBACK')
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        if form.continue_.data == 'yes':
            return redirect(url_for('member_insert', origin_id=origin_id))
        return redirect(url_for('actor_view', id_=origin.id) + '#tab-member')
    return render_template('member/insert.html', origin=origin, form=form)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:24,代码来源:member.py


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