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


Python entity.EntityMapper类代码示例

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


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

示例1: build_move_form

def build_move_form(form, node) -> Form:
    root = g.nodes[node.root[-1]]
    setattr(form, str(root.id), TreeField(str(root.id)))
    form_instance = form(obj=node)

    # Delete custom fields except the ones specified for the form
    delete_list = []  # Can't delete fields in the loop so creating a list for later deletion
    for field in form_instance:
        if type(field) is TreeField and int(field.id) != root.id:
            delete_list.append(field.id)
    for item in delete_list:
        delattr(form_instance, item)
    choices = []
    if root.class_.code == 'E53':
        for entity in node.get_linked_entities('P89', True):
            place = entity.get_linked_entity('P53', True)
            if place:
                choices.append((entity.id, place.name))
    elif root.name in app.config['PROPERTY_TYPES']:
        for row in LinkMapper.get_entities_by_node(node):
            domain = EntityMapper.get_by_id(row.domain_id)
            range_ = EntityMapper.get_by_id(row.range_id)
            choices.append((row.id, domain.name + ' - ' + range_.name))
    else:
        for entity in node.get_linked_entities('P2', True):
            choices.append((entity.id, entity.name))

    form_instance.selection.choices = choices
    return form_instance
开发者ID:stefaneichert,项目名称:openAtlas,代码行数:29,代码来源:forms.py

示例2: member_update

def member_update(id_, origin_id):
    link_ = LinkMapper.get_by_id(id_)
    domain = EntityMapper.get_by_id(link_.domain.id)
    range_ = EntityMapper.get_by_id(link_.range.id)
    origin = range_ if origin_id == range_.id else domain
    form = build_form(MemberForm, 'Member', link_, request)
    del form.actor, form.group, form.insert_and_continue
    if form.validate_on_submit():
        g.cursor.execute('BEGIN')
        try:
            link_.delete()
            link_id = domain.link('P107', range_, form.description.data)
            DateMapper.save_link_dates(link_id, form)
            NodeMapper.save_link_nodes(link_id, form)
            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')
        tab = '#tab-member-of' if origin.id == range_.id else '#tab-member'
        return redirect(url_for('actor_view', id_=origin.id) + tab)
    form.save.label.text = _('save')
    link_.set_dates()
    form.populate_dates(link_)
    related = range_ if origin_id == domain.id else domain
    return render_template('member/update.html', origin=origin, form=form, related=related)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:26,代码来源:member.py

示例3: involvement_update

def involvement_update(id_, origin_id):
    link_ = LinkMapper.get_by_id(id_)
    event = EntityMapper.get_by_id(link_.domain.id)
    actor = EntityMapper.get_by_id(link_.range.id)
    origin = event if origin_id == event.id else actor
    form = build_form(ActorForm, 'Involvement', link_, request)
    form.save.label.text = _('save')
    del form.actor, form.event, form.insert_and_continue
    form.activity.choices = [('P11', g.properties['P11'].name)]
    if event.class_.code in ['E7', 'E8', 'E12']:
        form.activity.choices.append(('P14', g.properties['P14'].name))
    if event.class_.code == 'E8':
        form.activity.choices.append(('P22', g.properties['P22'].name))
        form.activity.choices.append(('P23', g.properties['P23'].name))
    if form.validate_on_submit():
        g.cursor.execute('BEGIN')
        try:
            link_.delete()
            link_id = event.link(form.activity.data, actor, form.description.data)
            DateMapper.save_link_dates(link_id, form)
            NodeMapper.save_link_nodes(link_id, form)
            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')
        tab = 'actor' if origin.view_name == 'event' else 'event'
        return redirect(url_for(origin.view_name + '_view', id_=origin.id) + '#tab-' + tab)
    form.activity.data = link_.property.code
    form.description.data = link_.description
    link_.set_dates()
    form.populate_dates(link_)
    return render_template('involvement/update.html', origin=origin, form=form,
                           linked_object=event if origin_id != event.id else actor)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:34,代码来源:involvement.py

示例4: save_date

    def save_date(id_, form, name, code, link_mapper):
        """ Saves a date taken from a form and creates links to the entity

        :param id_: id of an entity of link
        :param form: a form with date fields
        :param name: can be a string with the values "begin" or "end"
        :param code: an OpenAtlas shortcut code e.g. 'OA5'
        :param link_mapper: whether to use LinkMapper (for entity) or LinkPropertyMapper (for link)
        :return:
        """
        from openatlas.models.entity import EntityMapper

        if not getattr(form, 'date_' + name + '_year').data:
            return  # return because no year given
        description = getattr(form, 'date_' + name + '_info').data

        date = {}  # put date form values in a dictionary
        for item in ['year', 'month', 'day', 'year2', 'month2', 'day2']:
            value = getattr(form, 'date_' + name + '_' + item).data
            date[item] = int(value) if value else ''

        if date['year2']:  # Time span
            date_from = DateMapper.form_to_datetime64(date['year'], date['month'], date['day'])
            date_from = EntityMapper.insert('E61', DateMapper.datetime64_to_timestamp(date_from),
                                            'from date value', description, date_from)
            link_mapper.insert(id_, code, date_from)
            date_to = DateMapper.form_to_datetime64(date['year2'], date['month2'], date['day2'])
            date_to = EntityMapper.insert('E61', DateMapper.datetime64_to_timestamp(date_to),
                                          system_type='to date value', date=date_to)
            link_mapper.insert(id_, code, date_to)
        else:  # Exact date
            date = DateMapper.form_to_datetime64(date['year'], date['month'], date['day'])
            exact_date = EntityMapper.insert('E61', DateMapper.datetime64_to_timestamp(date),
                                             'exact date value', description, date)
            link_mapper.insert(id_, code, exact_date)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:35,代码来源:date.py

示例5: index

def index():
    tables = {
        'counts': {'id': 'overview', 'header': [], 'data': [], 'show_pager': False},
        'bookmarks': {'id': 'bookmarks', 'data': [], 'show_pager': False,
                      'header': ['name', 'class', 'first', 'last']},
        'latest': {'id': 'latest', 'data': [], 'show_pager': False,
                   'header': ['name', 'class', 'first', 'last', 'date', 'user']}}
    if current_user.is_authenticated and hasattr(current_user, 'bookmarks'):
        for entity_id in current_user.bookmarks:
            entity = EntityMapper.get_by_id(entity_id)
            tables['bookmarks']['data'].append([
                link(entity),
                g.classes[entity.class_.code].name,
                entity.first,
                entity.last,
                bookmark_toggle(entity.id, True)])
        for name, count in EntityMapper.get_overview_counts().items():
            count = format_number(count) if count else ''
            tables['counts']['data'].append([
                '<a href="' + url_for(name + '_index') + '">' + uc_first(_(name)) + '</a>', count])
        for entity in EntityMapper.get_latest(8):
            tables['latest']['data'].append([
                link(entity),
                g.classes[entity.class_.code].name,
                entity.first,
                entity.last,
                format_date(entity.created),
                link(logger.get_log_for_advanced_view(entity.id)['creator'])])
    intro = ContentMapper.get_translation('intro')
    return render_template('index/index.html', intro=intro, tables=tables)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:30,代码来源:index.py

示例6: import_data

 def import_data(project, class_code, data):
     from openatlas.models.entity import EntityMapper
     for row in data:
         system_type = None
         if class_code == 'E33':  # pragma: no cover
             system_type = 'source content'
         elif class_code == 'E18':
             system_type = 'place'
         desc = row['description'] if 'description' in row and row['description'] else None
         entity = EntityMapper.insert(code=class_code,
                                      name=row['name'],
                                      description=desc,
                                      system_type=system_type)
         sql = """
             INSERT INTO import.entity (project_id, origin_id, entity_id, user_id)
             VALUES (%(project_id)s, %(origin_id)s, %(entity_id)s, %(user_id)s);"""
         g.cursor.execute(sql, {
             'project_id': project.id,
             'origin_id': row['id'] if 'id' in row and row['id'] else None,
             'entity_id': entity.id,
             'user_id': current_user.id})
         if class_code == 'E18':
             location = EntityMapper.insert(
                 'E53', 'Location of ' + row['name'], 'place location')
             entity.link('P53', location)
开发者ID:stefaneichert,项目名称:openAtlas,代码行数:25,代码来源:imports.py

示例7: relation_update

def relation_update(id_, origin_id):
    link_ = LinkMapper.get_by_id(id_)
    domain = EntityMapper.get_by_id(link_.domain.id)
    range_ = EntityMapper.get_by_id(link_.range.id)
    origin = range_ if origin_id == range_.id else domain
    related = range_ if origin_id == domain.id else domain
    form = build_form(RelationForm, 'Actor Actor Relation', link_, request)
    del form.actor, form.insert_and_continue, form.origin_id
    if form.validate_on_submit():
        g.cursor.execute('BEGIN')
        try:
            link_.delete()
            if form.inverse.data:
                link_id = related.link('OA7', origin, form.description.data)
            else:
                link_id = origin.link('OA7', related, form.description.data)
            DateMapper.save_link_dates(link_id, form)
            NodeMapper.save_link_nodes(link_id, form)
            g.cursor.execute('COMMIT')
            flash(_('info update'), 'info')
        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('actor_view', id_=origin.id) + '#tab-relation')
    if origin.id == range_.id:
        form.inverse.data = True
    form.save.label.text = _('save')
    link_.set_dates()
    form.populate_dates(link_)
    return render_template('relation/update.html', origin=origin, form=form, related=related)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:31,代码来源:relation.py

示例8: hierarchy_delete

def hierarchy_delete(id_):
    node = g.nodes[id_]
    if node.system or node.subs or node.count:
        abort(403)
    EntityMapper.delete(node.id)
    flash(_('entity deleted'), 'info')
    return redirect(url_for('node_index'))
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:7,代码来源:hierarchy.py

示例9: node_view

def node_view(id_):
    from openatlas.models.linkProperty import LinkPropertyMapper
    node = g.nodes[id_]
    root = g.nodes[node.root[-1]] if node.root else None
    super_ = g.nodes[node.root[0]] if node.root else None
    header = [_('name'), _('class'), _('info')]
    if root and root.value_type:  # pragma: no cover
        header = [_('name'), _('value'), _('class'), _('info')]
    tables = {'entities': {'id': 'entities', 'header': header, 'data': []},
              'info': get_entity_data(node)}

    for entity in node.get_linked_entities(['P2', 'P89'], True):
        # If it is a place location get the corresponding object
        entity = entity if node.class_.code == 'E55' else entity.get_linked_entity('P53', True)
        if entity:  # If not entity it is a place node, so do not add
            data = [link(entity)]
            if root and root.value_type:  # pragma: no cover
                data.append(format_number(entity.nodes[node]))
            data.append(g.classes[entity.class_.code].name)
            data.append(truncate_string(entity.description))
            tables['entities']['data'].append(data)
    tables['link_entities'] = {'id': 'link_items', 'header': [_('domain'), _('range')], 'data': []}
    for row in LinkPropertyMapper.get_entities_by_node(node):
        tables['link_entities']['data'].append([link(EntityMapper.get_by_id(row.domain_id)),
                                                link(EntityMapper.get_by_id(row.range_id))])
    tables['subs'] = {'id': 'subs', 'header': [_('name'), _('count'), _('info')], 'data': []}
    for sub_id in node.subs:
        sub = g.nodes[sub_id]
        tables['subs']['data'].append([link(sub), sub.count, truncate_string(sub.description)])
    return render_template('types/view.html', node=node, super_=super_, tables=tables, root=root)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:30,代码来源:types.py

示例10: build_table_form

def build_table_form(class_name, linked_entities):
    """ Returns a form with a list of entities with checkboxes"""
    from flask_wtf.csrf import generate_csrf
    from openatlas.models.entity import EntityMapper
    header = app.config['TABLE_HEADERS'][class_name] + ['']
    table = {'id': class_name, 'header': header, 'data': []}
    linked_ids = [entity.id for entity in linked_entities]
    file_stats = get_file_stats() if class_name == 'file' else None
    if class_name == 'file':
        entities = EntityMapper.get_by_system_type('file')
    elif class_name == 'place':
        entities = EntityMapper.get_by_system_type('place')
    else:
        entities = EntityMapper.get_by_codes(class_name)
    for entity in entities:
        if entity.id in linked_ids:
            continue  # Don't show already linked entries
        input_ = '<input id="{id}" name="values" type="checkbox" value="{id}">'.format(id=entity.id)
        table['data'].append(get_base_table_data(entity, file_stats) + [input_])
    if not table['data']:
        return uc_first(_('no entries'))
    return """<form class="table" method="post">
                <input id="csrf_token" name="csrf_token" type="hidden" value="{token}">
                {pager} <button name="form-submit" id="form-submit" type="submit">{add}</button>
              </form>""".format(add=uc_first(_('add')), pager=pager(table), token=generate_csrf())
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:25,代码来源:util.py

示例11: reference_add

def reference_add(origin_id):
    """ Link an entity to reference coming from the entity."""
    origin = EntityMapper.get_by_id(origin_id)
    form = AddReferenceForm()
    if form.validate_on_submit():
        EntityMapper.get_by_id(form.reference.data).link('P67', origin, form.page.data)
        return redirect(url_for(origin.view_name + '_view', id_=origin.id) + '#tab-reference')
    return render_template('reference/add.html', origin=origin, form=form)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:8,代码来源:reference.py

示例12: node_delete

def node_delete(id_):
    node = g.nodes[id_]
    if node.system or node.subs or node.count:
        abort(403)
    EntityMapper.delete(node.id)
    flash(_('entity deleted'), 'info')
    root = g.nodes[node.root[-1]] if node.root else None
    return redirect(url_for('node_view', id_=root.id) if root else url_for('node_index'))
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:8,代码来源:types.py

示例13: source_add2

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,代码行数:9,代码来源:source.py

示例14: reference_add2

def reference_add2(reference_id, class_name):
    """ Link an entity to reference coming from the reference."""
    reference_ = EntityMapper.get_by_id(reference_id)
    form = getattr(openatlas.views.reference, 'Add' + uc_first(class_name) + 'Form')()
    if form.validate_on_submit():
        property_code = 'P128' if reference_.class_.code == 'E84' else 'P67'
        entity = EntityMapper.get_by_id(getattr(form, class_name).data)
        reference_.link(property_code, entity, form.page.data)
        return redirect(url_for('reference_view', id_=reference_.id) + '#tab-' + class_name)
    return render_template('reference/add2.html', reference=reference_, form=form,
                           class_name=class_name)
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:11,代码来源:reference.py

示例15: save

def save(form, actor=None, code=None, origin=None):
    g.cursor.execute('BEGIN')
    try:
        log_action = 'update'
        if actor:
            actor.delete_links(['P74', 'OA8', 'OA9'])
            for alias in actor.get_linked_entities('P131'):
                alias.delete()
        else:
            actor = EntityMapper.insert(code, form.name.data)
            log_action = 'insert'
        actor.name = form.name.data
        actor.description = form.description.data
        actor.update()
        actor.save_dates(form)
        actor.save_nodes(form)
        url = url_for('actor_view', id_=actor.id)
        if form.residence.data:
            object_ = EntityMapper.get_by_id(form.residence.data)
            actor.link('P74', object_.get_linked_entity('P53'))
        if form.appears_first.data:
            object_ = EntityMapper.get_by_id(form.appears_first.data)
            actor.link('OA8', object_.get_linked_entity('P53'))
        if form.appears_last.data:
            object_ = EntityMapper.get_by_id(form.appears_last.data)
            actor.link('OA9', object_.get_linked_entity('P53'))
        for alias in form.alias.data:
            if alias.strip():  # Check if it isn't empty
                actor.link('P131', EntityMapper.insert('E82', alias))
        if origin:
            if origin.view_name == 'reference':
                link_id = origin.link('P67', actor)
                url = url_for('reference_link_update', link_id=link_id, origin_id=origin.id)
            elif origin.view_name == 'source':
                origin.link('P67', actor)
                url = url_for('source_view', id_=origin.id) + '#tab-actor'
            elif origin.view_name == 'event':
                link_id = origin.link('P11', actor)
                url = url_for('involvement_update', id_=link_id, origin_id=origin.id)
            elif origin.view_name == 'actor':
                link_id = origin.link('OA7', actor)
                url = url_for('relation_update', id_=link_id, origin_id=origin.id)
        if form.continue_.data == 'yes' and code:
            url = url_for('actor_insert', code=code)
        logger.log_user(actor.id, log_action)
        g.cursor.execute('COMMIT')
        flash(_('entity created') if log_action == 'insert' else _('info update'), 'info')
    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('actor_index'))
    return url
开发者ID:DigitisingPatternsOfPower,项目名称:OpenAtlas,代码行数:53,代码来源:actor.py


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