Beispiel #1
0
def object_view(id_: int) -> str:
    object_ = EntityMapper.get_by_id(id_, nodes=True)
    object_.note = UserMapper.get_note(object_)
    tables = {
        'info': get_entity_data(object_),
        'source': Table(Table.HEADERS['source']),
        'event': Table(Table.HEADERS['event'])
    }
    for link_ in object_.get_links('P128'):
        data = get_base_table_data(link_.range)
        if is_authorized('contributor'):
            url = url_for('link_delete', id_=link_.id, origin_id=object_.id)
            data.append(
                display_remove_link(url + '#tab-' + link_.range.table_name,
                                    link_.range.name))
        tables['source'].rows.append(data)
    for link_ in object_.get_links('P25', inverse=True):
        data = get_base_table_data(link_.domain)
        if is_authorized('contributor'):
            url = url_for('link_delete', id_=link_.id, origin_id=object_.id)
            data.append(
                display_remove_link(url + '#tab-' + link_.range.table_name,
                                    link_.range.name))
        tables['event'].rows.append(data)
    return render_template('object/view.html', object_=object_, tables=tables)
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)
def reference_view(id_):
    reference = EntityMapper.get_by_id(id_)
    tables = {
        'info': get_entity_data(reference),
        'file': {'id': 'files', 'data': [],
                 'header': app.config['TABLE_HEADERS']['file'] + ['page'] + [_('main image')]}}
    for name in ['source', 'event', 'actor', 'place', 'feature', 'stratigraphic-unit', 'find']:
        header = app.config['TABLE_HEADERS'][name] + ['page']
        tables[name] = {'id': name, 'header': header, 'data': []}
    for link_ in reference.get_links('P67', True):
        domain = link_.domain
        data = get_base_table_data(domain)
        if is_authorized('editor'):
            url = url_for('link_delete', id_=link_.id, origin_id=reference.id) + '#tab-file'
            data.append(display_remove_link(url, domain.name))
        tables['file']['data'].append(data)
    profile_image_id = reference.get_profile_image_id()
    for link_ in reference.get_links(['P67', 'P128']):
        range_ = link_.range
        data = get_base_table_data(range_)
        data.append(truncate_string(link_.description))
        if range_.view_name == 'file':  # pragma: no cover
            ext = data[3].replace('.', '')
            data.append(get_profile_image_table_link(range_, reference, ext, profile_image_id))
            if not profile_image_id and ext in app.config['DISPLAY_FILE_EXTENSIONS']:
                profile_image_id = range_.id
        if is_authorized('editor'):
            url = url_for('reference_link_update', link_id=link_.id, origin_id=reference.id)
            data.append('<a href="' + url + '">' + uc_first(_('edit')) + '</a>')
            url = url_for('link_delete', id_=link_.id, origin_id=reference.id)
            data.append(display_remove_link(url + '#tab-' + range_.table_name, range_.name))
        tables[range_.table_name]['data'].append(data)
    return render_template('reference/view.html', reference=reference, tables=tables,
                           profile_image_id=profile_image_id)
Beispiel #4
0
def translation_view(id_):
    translation = EntityMapper.get_by_id(id_)
    source = translation.get_linked_entity('P73', True)
    return render_template('translation/view.html',
                           source=source,
                           translation=translation,
                           tables={'info': get_entity_data(translation)})
def event_view(id_):
    event = EntityMapper.get_by_id(id_)
    event.set_dates()
    tables = {
        'info': get_entity_data(event),
        'file': {'id': 'files', 'data': [],
                 'header': app.config['TABLE_HEADERS']['file'] + [_('main image')]},
        'subs': {'id': 'sub-event', 'data': [], 'header': app.config['TABLE_HEADERS']['event']},
        'source': {'id': 'source', 'data': [], 'header': app.config['TABLE_HEADERS']['source']},
        'actor': {'id': 'actor', 'data': [],
                  'header': ['actor', 'class', 'involvement', 'first', 'last', 'description']},
        'reference': {'id': 'reference', 'data': [],
                      'header': app.config['TABLE_HEADERS']['reference'] + ['pages']}}
    for link_ in event.get_links(['P11', 'P14', 'P22', 'P23']):
        first = link_.first
        if not link_.first and event.first:
            first = '<span class="inactive" style="float:right">' + str(event.first) + '</span>'
        last = link_.last
        if not link_.last and event.last:
            last = '<span class="inactive" style="float:right">' + str(event.last) + '</span>'
        data = ([link(link_.range),
                 g.classes[link_.range.class_.code].name,
                 link_.type.name if link_.type else '',
                 first, last,
                 truncate_string(link_.description)])
        if is_authorized('editor'):
            update_url = url_for('involvement_update', id_=link_.id, origin_id=event.id)
            unlink_url = url_for('link_delete', id_=link_.id, origin_id=event.id) + '#tab-actor'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables['actor']['data'].append(data)
    profile_image_id = event.get_profile_image_id()
    for link_ in event.get_links('P67', True):
        domain = link_.domain
        data = get_base_table_data(domain)
        if domain.view_name == 'file':  # pragma: no cover
            extension = data[3].replace('.', '')
            data.append(get_profile_image_table_link(domain, event, extension, profile_image_id))
            if not profile_image_id and extension in app.config['DISPLAY_FILE_EXTENSIONS']:
                profile_image_id = domain.id
        if domain.view_name not in ['source', 'file']:
            data.append(truncate_string(link_.description))
            if is_authorized('editor'):
                update_url = url_for('reference_link_update', link_id=link_.id, origin_id=event.id)
                data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            url = url_for('link_delete', id_=link_.id, origin_id=event.id)
            data.append(display_remove_link(url + '#tab-' + domain.view_name, domain.name))
        tables[domain.view_name]['data'].append(data)
    for sub_event in event.get_linked_entities('P117', True):
        tables['subs']['data'].append(get_base_table_data(sub_event))
    return render_template('event/view.html', event=event, tables=tables,
                           profile_image_id=profile_image_id)
Beispiel #6
0
def reference_view(id_: int) -> str:
    reference = EntityMapper.get_by_id(id_, nodes=True)
    reference.note = UserMapper.get_note(reference)
    tables = {
        'info': get_entity_data(reference),
        'file': Table(Table.HEADERS['file'] + ['page', _('main image')])
    }
    for name in [
            'source', 'event', 'actor', 'place', 'feature',
            'stratigraphic-unit', 'find'
    ]:
        header_label = 'link text' if reference.system_type == 'external reference' else 'page'
        tables[name] = Table(Table.HEADERS[name] + [header_label])
    for link_ in reference.get_links('P67', True):
        domain = link_.domain
        data = get_base_table_data(domain)
        if is_authorized('contributor'):
            url = url_for('link_delete', id_=link_.id,
                          origin_id=reference.id) + '#tab-file'
            data.append(display_remove_link(url, domain.name))
        tables['file'].rows.append(data)
    profile_image_id = reference.get_profile_image_id()
    for link_ in reference.get_links(['P67', 'P128']):
        range_ = link_.range
        data = get_base_table_data(range_)
        data.append(truncate_string(link_.description))
        if range_.view_name == 'file':  # pragma: no cover
            ext = data[3].replace('.', '')
            data.append(
                get_profile_image_table_link(range_, reference, ext,
                                             profile_image_id))
            if not profile_image_id and ext in app.config[
                    'DISPLAY_FILE_EXTENSIONS']:
                profile_image_id = range_.id
        if is_authorized('contributor'):
            url = url_for('reference_link_update',
                          link_id=link_.id,
                          origin_id=reference.id)
            data.append('<a href="' + url + '">' + uc_first(_('edit')) +
                        '</a>')
            url = url_for('link_delete', id_=link_.id, origin_id=reference.id)
            data.append(
                display_remove_link(url + '#tab-' + range_.table_name,
                                    range_.name))
        tables[range_.table_name].rows.append(data)
    return render_template('reference/view.html',
                           reference=reference,
                           tables=tables,
                           profile_image_id=profile_image_id)
Beispiel #7
0
def reference_view(id_, unlink_id=None):
    reference = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    tables = {
        'info': get_entity_data(reference),
        'file': {
            'id': 'files',
            'data': [],
            'header': app.config['TABLE_HEADERS']['file'] + ['page']
        }
    }
    for name in [
            'source', 'event', 'actor', 'place', 'feature',
            'stratigraphic-unit', 'find'
    ]:
        header = app.config['TABLE_HEADERS'][name] + ['page']
        tables[name] = {'id': name, 'header': header, 'data': []}
    for link_ in reference.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        if is_authorized('editor'):
            unlink = url_for('reference_view',
                             id_=reference.id,
                             unlink_id=link_.id) + '#tab-file'
            data.append(display_remove_link(unlink, link_.domain.name))
        tables['file']['data'].append(data)
    for link_ in reference.get_links(['P67', 'P128']):
        view_name = get_view_name(link_.range)
        view_name = view_name if view_name != 'place' else link_.range.system_type.replace(
            ' ', '-')
        data = get_base_table_data(link_.range)
        data.append(truncate_string(link_.description))
        if is_authorized('editor'):
            update_url = url_for('reference_link_update',
                                 link_id=link_.id,
                                 origin_id=reference.id)
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            unlink_url = url_for('reference_view',
                                 id_=reference.id,
                                 unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables[view_name]['data'].append(data)
    return render_template('reference/view.html',
                           reference=reference,
                           tables=tables)
Beispiel #8
0
def file_view(id_: int) -> str:
    file = EntityMapper.get_by_id(id_, nodes=True)
    path = get_file_path(file.id)
    tables = {'info': get_entity_data(file)}
    for name in [
            'source', 'event', 'actor', 'place', 'feature',
            'stratigraphic-unit', 'find', 'reference'
    ]:
        tables[name] = Table(Table.HEADERS[name] +
                             (['page'] if name == 'reference' else []))
    for link_ in file.get_links('P67'):
        range_ = link_.range
        data = get_base_table_data(range_)
        view_name = range_.view_name
        view_name = view_name if view_name != 'place' else range_.system_type.replace(
            ' ', '-')
        if is_authorized('contributor'):
            url = url_for('link_delete', id_=link_.id, origin_id=file.id)
            data.append(
                display_remove_link(url + '#tab-' + view_name, range_.name))
        tables[view_name].rows.append(data)
    for link_ in file.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        data.append(link_.description)
        if is_authorized('contributor'):
            update_url = url_for('reference_link_update',
                                 link_id=link_.id,
                                 origin_id=file.id)
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            unlink_url = url_for('link_delete',
                                 id_=link_.id,
                                 origin_id=file.id)
            data.append(
                display_remove_link(unlink_url + '#tab-reference',
                                    link_.domain.name))
        tables['reference'].rows.append(data)
    return render_template(
        'file/view.html',
        missing_file=False if path else True,
        entity=file,
        tables=tables,
        preview=True if path and preview_file(path) else False,
        filename=os.path.basename(path) if path else False)
Beispiel #9
0
def file_view(id_, unlink_id=None):
    file = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    path = get_file_path(file.id)
    tables = {'info': get_entity_data(file)}
    for name in [
            'source', 'event', 'actor', 'place', 'feature',
            'stratigraphic-unit', 'find', 'reference'
    ]:
        header = app.config['TABLE_HEADERS'][name] + (['page'] if name
                                                      == 'reference' else [])
        tables[name] = {'id': name, 'data': [], 'header': header}
    for link_ in file.get_links('P67'):
        view_name = get_view_name(link_.range)
        view_name = view_name if view_name != 'place' else link_.range.system_type.replace(
            ' ', '-')
        data = get_base_table_data(link_.range)
        if is_authorized('editor'):
            unlink_url = url_for('file_view', id_=file.id,
                                 unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables[view_name]['data'].append(data)
    for link_ in file.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        data.append(link_.description)
        if is_authorized('editor'):
            update_url = url_for('reference_link_update',
                                 link_id=link_.id,
                                 origin_id=file.id)
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            unlink_url = url_for('file_view', id_=file.id,
                                 unlink_id=link_.id) + '#tab-reference'
            data.append(display_remove_link(unlink_url, link_.domain.name))
        tables['reference']['data'].append(data)
    return render_template(
        'file/view.html',
        missing_file=False if path else True,
        entity=file,
        tables=tables,
        preview=True if path and preview_file(path) else False,
        filename=os.path.basename(path) if path else False)
def source_view(id_):
    source = EntityMapper.get_by_id(id_)
    tables = {
        'info': get_entity_data(source),
        'text': {'id': 'translation', 'data': [], 'header': ['text', 'type', 'content']},
        'file': {'id': 'files', 'data': [],
                 'header': app.config['TABLE_HEADERS']['file'] + [_('main image')]},
        'reference': {'id': 'source', 'data': [],
                      'header': app.config['TABLE_HEADERS']['reference'] + ['page']}}
    for text in source.get_linked_entities('P73'):
        tables['text']['data'].append([
            link(text),
            next(iter(text.nodes)).name if text.nodes else '',
            truncate_string(text.description)])
    for name in ['actor', 'event', 'place', 'feature', 'stratigraphic-unit', 'find']:
        tables[name] = {'id': name, 'header': app.config['TABLE_HEADERS'][name], 'data': []}
    for link_ in source.get_links('P67'):
        range_ = link_.range
        data = get_base_table_data(range_)
        if is_authorized('editor'):
            url = url_for('link_delete', id_=link_.id, origin_id=source.id)
            data.append(display_remove_link(url + '#tab-' + range_.table_name, range_.name))
        tables[range_.table_name]['data'].append(data)
    profile_image_id = source.get_profile_image_id()
    for link_ in source.get_links(['P67', 'P128'], True):
        domain = link_.domain
        data = get_base_table_data(domain)
        if domain.view_name == 'file':  # pragma: no cover
            extension = data[3].replace('.', '')
            data.append(get_profile_image_table_link(domain, source, extension, profile_image_id))
            if not profile_image_id and extension in app.config['DISPLAY_FILE_EXTENSIONS']:
                profile_image_id = domain.id
        if domain.view_name not in ['file']:
            data.append(link_.description)
            if is_authorized('editor'):
                update_url = url_for('reference_link_update', link_id=link_.id, origin_id=source.id)
                data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            url = url_for('link_delete', id_=link_.id, origin_id=source.id)
            data.append(display_remove_link(url + '#tab-' + domain.view_name, domain.name))
        tables[domain.view_name]['data'].append(data)
    return render_template('source/view.html', source=source, tables=tables,
                           profile_image_id=profile_image_id)
Beispiel #11
0
def source_view(id_, unlink_id=None):
    source = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    tables = {
        'info': get_entity_data(source),
        'text': {'id': 'translation', 'data': [], 'header': ['text', 'type', 'content']},
        'file': {'id': 'files', 'data': [], 'header': app.config['TABLE_HEADERS']['file']},
        'reference': {
            'id': 'source', 'data': [],
            'header': app.config['TABLE_HEADERS']['reference'] + ['page']}}
    for text in source.get_linked_entities('P73'):
        tables['text']['data'].append([
            link(text),
            next(iter(text.nodes)).name if text.nodes else '',
            truncate_string(text.description)])
    for name in ['actor', 'event', 'place', 'feature', 'stratigraphic-unit', 'find']:
        tables[name] = {'id': name, 'header': app.config['TABLE_HEADERS'][name], 'data': []}
    for link_ in source.get_links('P67'):
        data = get_base_table_data(link_.range)
        view_name = get_view_name(link_.range)
        view_name = view_name if view_name != 'place' else link_.range.system_type.replace(' ', '-')
        if is_authorized('editor'):
            unlink = url_for('source_view', id_=source.id, unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink, link_.range.name))
        tables[view_name]['data'].append(data)
    for link_ in source.get_links(['P67', 'P128'], True):
        data = get_base_table_data(link_.domain)
        view_name = get_view_name(link_.domain)
        if view_name not in ['file']:
            data.append(link_.description)
            if is_authorized('editor'):
                update_url = url_for('reference_link_update', link_id=link_.id, origin_id=source.id)
                data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            unlink = url_for('source_view', id_=source.id, unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink, link_.domain.name))
        tables[view_name]['data'].append(data)
    return render_template('source/view.html', source=source, tables=tables)
Beispiel #12
0
def node_view(id_: int) -> str:
    from openatlas.models.link import LinkMapper
    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 = {'info': get_entity_data(node), 'entities': Table(header)}
    for entity in node.get_linked_entities(['P2', 'P89'],
                                           inverse=True,
                                           nodes=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'].rows.append(data)
    tables['link_entities'] = Table([_('domain'), _('range')])
    for row in LinkMapper.get_entities_by_node(node):
        tables['link_entities'].rows.append([
            link(EntityMapper.get_by_id(row.domain_id)),
            link(EntityMapper.get_by_id(row.range_id))
        ])
    tables['subs'] = Table([_('name'), _('count'), _('info')])
    for sub_id in node.subs:
        sub = g.nodes[sub_id]
        tables['subs'].rows.append(
            [link(sub), sub.count,
             truncate_string(sub.description)])
    return render_template('types/view.html',
                           node=node,
                           super_=super_,
                           tables=tables,
                           root=root)
Beispiel #13
0
def view(id_: int) -> Union[str, Response]:
    if id_ in g.types:  # Types have their own view
        entity = g.types[id_]
        if not entity.root:
            return redirect(
                f"{url_for('type_index')}"
                f"#menu-tab-{entity.category}_collapse-{id_}")
    elif id_ in g.reference_systems:
        entity = g.reference_systems[id_]
    else:
        entity = Entity.get_by_id(id_, types=True, aliases=True)
        if not entity.class_.view:
            flash(_("This entity can't be viewed directly."), 'error')
            abort(400)

    event_links = None  # Needed for actor and info data
    tabs = {'info': Tab('info')}
    if isinstance(entity, Type):
        tabs |= add_tabs_for_type(entity)
    elif isinstance(entity, ReferenceSystem):
        tabs |= add_tabs_for_reference_system(entity)
    elif entity.class_.view == 'actor':
        event_links = entity.get_links(
            ['P11', 'P14', 'P22', 'P23', 'P25'],
            True)
        tabs |= add_tabs_for_actor(entity, event_links)
    elif entity.class_.view == 'artifact':
        tabs['source'] = Tab('source', entity=entity)
    elif entity.class_.view == 'event':
        tabs |= add_tabs_for_event(entity)
    elif entity.class_.view == 'file':
        tabs |= add_tabs_for_file(entity)
    elif entity.class_.view == 'place':
        tabs |= add_tabs_for_place(entity)
    elif entity.class_.view == 'reference':
        tabs |= add_tabs_for_reference(entity)
    elif entity.class_.view == 'source':
        tabs |= add_tabs_for_source(entity)

    overlays = None  # Needed for place
    if entity.class_.view in [
            'actor', 'artifact', 'event', 'place', 'source', 'type']:
        if not isinstance(entity, Type):
            tabs['reference'] = Tab('reference', entity=entity)
        if entity.class_.view == 'artifact':
            tabs['event'] = Tab('event', entity=entity)
            for link_ in entity.get_links(['P25', 'P108'], True):
                data = get_base_table_data(link_.domain)
                tabs['event'].table.rows.append(data)
        tabs['file'] = Tab('file', entity=entity)
        entity.image_id = entity.get_profile_image_id()
        if entity.class_.view == 'place' \
                and is_authorized('editor') \
                and current_user.settings['module_map_overlay']:
            tabs['file'].table.header.append(uc_first(_('overlay')))
        for link_ in entity.get_links('P67', inverse=True):
            domain = link_.domain
            data = get_base_table_data(domain)
            if domain.class_.view == 'file':  # pragma: no cover
                extension = data[3]
                data.append(
                    get_profile_image_table_link(
                        domain,
                        entity,
                        extension,
                        entity.image_id))
                if not entity.image_id \
                        and extension in app.config['DISPLAY_FILE_EXTENSIONS']:
                    entity.image_id = domain.id
                if entity.class_.view == 'place' \
                        and is_authorized('editor') \
                        and current_user.settings['module_map_overlay']:
                    overlays = Overlay.get_by_object(entity)
                    if extension in app.config['DISPLAY_FILE_EXTENSIONS']:
                        if domain.id in overlays:
                            data.append(edit_link(
                                url_for(
                                    'overlay_update',
                                    id_=overlays[domain.id].id)))
                        else:
                            data.append(link(_('link'), url_for(
                                'overlay_insert',
                                image_id=domain.id,
                                place_id=entity.id,
                                link_id=link_.id)))
                    else:  # pragma: no cover
                        data.append('')
            if domain.class_.view not in ['source', 'file']:
                data.append(link_.description)
                data.append(edit_link(
                    url_for('link_update', id_=link_.id, origin_id=entity.id)))
                if domain.class_.view == 'reference_system':
                    entity.reference_systems.append(link_)
                    continue
            data.append(
                remove_link(domain.name, link_, entity, domain.class_.view))
            tabs[domain.class_.view].table.rows.append(data)

    if 'file' in tabs \
            and current_user.settings['table_show_icons'] \
            and g.settings['image_processing']:
        tabs['file'].table.header.insert(1, uc_first(_('icon')))
        for row in tabs['file'].table.rows:
            row.insert(
                1,
                file_preview(
                    int(row[0].replace('<a href="/entity/', '').split('"')[0]))
            )

    place_structure = None
    gis_data = None
    if entity.class_.view in ['artifact', 'place']:
        place_structure = get_structure(entity)
        if place_structure:
            for item in place_structure['subunits']:
                tabs[item.class_.name].table.rows.append(
                    get_base_table_data(item))
        gis_data = Gis.get_all([entity], place_structure)
        if gis_data['gisPointSelected'] == '[]' \
                and gis_data['gisPolygonSelected'] == '[]' \
                and gis_data['gisLineSelected'] == '[]' \
                and (not place_structure or not place_structure['super_id']):
            gis_data = {}
    entity.info_data = get_entity_data(entity, event_links=event_links)
    if not gis_data:  # Has to be after get_entity_data()
        gis_data = Gis.get_all(entity.linked_places) \
            if entity.linked_places else None
    problematic_type_id = entity.check_for_too_many_links_for_single_type()
    tabs['note'] = add_note_tab(entity)
    tabs['info'].content = render_template(
        'entity/view.html',
        buttons=add_buttons(entity, bool(problematic_type_id)),
        entity=entity,
        gis_data=gis_data,
        structure=place_structure,
        overlays=overlays,
        title=entity.name,
        problematic_type_id=problematic_type_id)
    return render_template(
        'tabs.html',
        tabs=tabs,
        gis_data=gis_data,
        crumbs=add_crumbs(entity, place_structure),
        entity=entity)
Beispiel #14
0
def place_view(id_, unlink_id=None):
    object_ = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    object_.set_dates()
    location = object_.get_linked_entity('P53')
    tables = {
        'info': get_entity_data(object_, location),
        'file': {'id': 'files', 'data': [], 'header': app.config['TABLE_HEADERS']['file']},
        'source': {'id': 'source', 'data': [], 'header': app.config['TABLE_HEADERS']['source']},
        'event': {'id': 'event', 'data': [], 'header': app.config['TABLE_HEADERS']['event']},
        'reference': {
            'id': 'reference', 'data': [],
            'header': app.config['TABLE_HEADERS']['reference'] + ['pages']},
        'actor': {
            'id': 'actor', 'data': [],
            'header': [_('actor'), _('property'), _('class'), _('first'), _('last')]}}
    if object_.system_type == 'place':
        tables['feature'] = {'id': 'feature', 'data': [],
                             'header': app.config['TABLE_HEADERS']['place'] + [_('description')]}
    if object_.system_type == 'feature':
        tables['stratigraphic-unit'] = {
            'id': 'stratigraphic', 'data': [], 'header':
            app.config['TABLE_HEADERS']['place'] + [_('description')]}
    if object_.system_type == 'stratigraphic unit':
        tables['find'] = {'id': 'find', 'data': [],
                          'header': app.config['TABLE_HEADERS']['place'] + [_('description')]}
    for link_ in object_.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        view_name = get_view_name(link_.domain)
        if view_name not in ['source', 'file']:
            data.append(truncate_string(link_.description))
            if is_authorized('editor'):
                url = url_for('reference_link_update', link_id=link_.id, origin_id=object_.id)
                data.append('<a href="' + url + '">' + uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            url = url_for('place_view', id_=object_.id, unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(url, link_.domain.name))
        tables[view_name]['data'].append(data)
    for event in location.get_linked_entities(['P7', 'P24'], True):
        tables['event']['data'].append(get_base_table_data(event))
    has_subunits = False
    for entity in object_.get_linked_entities('P46'):
        has_subunits = True
        data = get_base_table_data(entity)
        data.append(truncate_string(entity.description))
        tables[entity.system_type.replace(' ', '-')]['data'].append(data)
    for link_ in location.get_links(['P74', 'OA8', 'OA9'], True):
        actor = EntityMapper.get_by_id(link_.domain.id)
        tables['actor']['data'].append([
            link(actor),
            g.properties[link_.property.code].name,
            actor.class_.name,
            actor.first,
            actor.last])
    gis_data = GisMapper.get_all(object_.id) if location else None
    if gis_data['gisPointSelected'] == '[]' and gis_data['gisPolygonSelected'] == '[]':
        gis_data = None
    place = None
    feature = None
    stratigraphic_unit = None
    if object_.system_type == 'find':
        stratigraphic_unit = object_.get_linked_entity('P46', True)
        feature = stratigraphic_unit.get_linked_entity('P46', True)
        place = feature.get_linked_entity('P46', True)
    elif object_.system_type == 'stratigraphic unit':
        feature = object_.get_linked_entity('P46', True)
        place = feature.get_linked_entity('P46', True)
    elif object_.system_type == 'feature':
        place = object_.get_linked_entity('P46', True)
    return render_template('place/view.html', object_=object_, tables=tables, gis_data=gis_data,
                           place=place, feature=feature, stratigraphic_unit=stratigraphic_unit,
                           has_subunits=has_subunits)
Beispiel #15
0
def event_view(id_: int) -> str:
    event = EntityMapper.get_by_id(id_, nodes=True)
    event.note = UserMapper.get_note(event)
    tables = {
        'info':
        get_entity_data(event),
        'file':
        Table(Table.HEADERS['file'] + [_('main image')]),
        'subs':
        Table(Table.HEADERS['event']),
        'source':
        Table(Table.HEADERS['source']),
        'actor':
        Table(
            ['actor', 'class', 'involvement', 'first', 'last', 'description'],
            defs='[{className: "dt-body-right", targets: [3,4]}]'),
        'reference':
        Table(Table.HEADERS['reference'] + ['page / link text'])
    }
    for link_ in event.get_links(['P11', 'P14', 'P22', 'P23']):
        first = link_.first
        if not link_.first and event.first:
            first = '<span class="inactive" style="float:right;">' + event.first + '</span>'
        last = link_.last
        if not link_.last and event.last:
            last = '<span class="inactive" style="float:right;">' + event.last + '</span>'
        data = ([
            link(link_.range), g.classes[link_.range.class_.code].name,
            link_.type.name if link_.type else '', first, last,
            truncate_string(link_.description)
        ])
        if is_authorized('contributor'):
            update_url = url_for('involvement_update',
                                 id_=link_.id,
                                 origin_id=event.id)
            unlink_url = url_for(
                'link_delete', id_=link_.id, origin_id=event.id) + '#tab-actor'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables['actor'].rows.append(data)
    profile_image_id = event.get_profile_image_id()
    for link_ in event.get_links('P67', True):
        domain = link_.domain
        data = get_base_table_data(domain)
        if domain.view_name == 'file':
            extension = data[3].replace('.', '')
            data.append(
                get_profile_image_table_link(domain, event, extension,
                                             profile_image_id))
            if not profile_image_id and extension in app.config[
                    'DISPLAY_FILE_EXTENSIONS']:
                profile_image_id = domain.id
        if domain.view_name not in ['source', 'file']:
            if domain.system_type == 'external reference':
                event.external_references.append(link_)
            data.append(truncate_string(link_.description))
            if is_authorized('contributor'):
                url = url_for('reference_link_update',
                              link_id=link_.id,
                              origin_id=event.id)
                data.append('<a href="' + url + '">' + uc_first(_('edit')) +
                            '</a>')
        if is_authorized('contributor'):
            url = url_for('link_delete', id_=link_.id, origin_id=event.id)
            data.append(
                display_remove_link(url + '#tab-' + domain.view_name,
                                    domain.name))
        tables[domain.view_name].rows.append(data)
    for sub_event in event.get_linked_entities('P117',
                                               inverse=True,
                                               nodes=True):
        tables['subs'].rows.append(get_base_table_data(sub_event))
    objects = []
    for location in event.get_linked_entities(['P7', 'P26', 'P27']):
        objects.append(location.get_linked_entity('P53', True))
    return render_template(
        'event/view.html',
        event=event,
        tables=tables,
        profile_image_id=profile_image_id,
        gis_data=GisMapper.get_all(objects) if objects else None)
def actor_view(id_):
    actor = EntityMapper.get_by_id(id_)
    actor.set_dates()
    objects = []
    info = get_entity_data(actor)
    residence = actor.get_linked_entity('P74')
    if residence:
        object_ = residence.get_linked_entity('P53', True)
        objects.append(object_)
        info.append((uc_first(_('residence')), link(object_)))
    first = actor.get_linked_entity('OA8')
    if first:
        object_ = first.get_linked_entity('P53', True)
        objects.append(object_)
        info.append((uc_first(_('appears first')), link(object_)))
    last = actor.get_linked_entity('OA9')
    if last:
        object_ = last.get_linked_entity('P53', True)
        objects.append(object_)
        info.append((uc_first(_('appears last')), link(object_)))
    tables = {
        'info': info,
        'file': {'id': 'files', 'data': [],
                 'header': app.config['TABLE_HEADERS']['file'] + [_('main image')]},
        'source': {'id': 'source', 'data': [], 'header': app.config['TABLE_HEADERS']['source']},
        'reference': {'id': 'reference', 'data': [],
                      'header': app.config['TABLE_HEADERS']['reference'] + ['pages']},
        'event': {'id': 'event', 'data': [],
                  'header': ['event', 'class', 'involvement', 'first', 'last', 'description']},
        'relation': {'id': 'relation', 'data': [], 'sort': 'sortList:[[0,0]]',
                     'header': ['relation', 'actor', 'first', 'last', 'description']},
        'member_of': {'id': 'member_of', 'data': [],
                      'header': ['member of', 'function', 'first', 'last', 'description']}}
    profile_image_id = actor.get_profile_image_id()
    for link_ in actor.get_links('P67', True):
        domain = link_.domain
        data = get_base_table_data(domain)
        if domain.view_name == 'file':
            extension = data[3].replace('.', '')
            data.append(get_profile_image_table_link(domain, actor, extension, profile_image_id))
            if not profile_image_id and extension in app.config['DISPLAY_FILE_EXTENSIONS']:
                profile_image_id = domain.id
        if domain.view_name not in ['source', 'file']:
            data.append(truncate_string(link_.description))
            if is_authorized('editor'):
                update_url = url_for('reference_link_update', link_id=link_.id, origin_id=actor.id)
                data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            url = url_for('link_delete', id_=link_.id, origin_id=actor.id)
            data.append(display_remove_link(url + '#tab-' + domain.view_name, domain.name))
        tables[domain.view_name]['data'].append(data)

    # Todo: Performance - getting every place of every object for every event is very costly
    for link_ in actor.get_links(['P11', 'P14', 'P22', 'P23'], True):
        event = link_.domain
        first = link_.first
        place = event.get_linked_entity('P7')
        if place:
            objects.append(place.get_linked_entity('P53', True))
        if not link_.first and event.first:
            first = '<span class="inactive" style="float:right">' + str(event.first) + '</span>'
        last = link_.last
        if not link_.last and event.last:
            last = '<span class="inactive" style="float:right">' + str(event.last) + '</span>'
        data = ([link(event),
                 g.classes[event.class_.code].name,
                 link_.type.name if link_.type else '',
                 first,
                 last,
                 truncate_string(link_.description)])
        if is_authorized('editor'):
            update_url = url_for('involvement_update', id_=link_.id, origin_id=actor.id)
            unlink_url = url_for('link_delete', id_=link_.id, origin_id=actor.id) + '#tab-event'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
            data.append(display_remove_link(unlink_url, link_.domain.name))
        tables['event']['data'].append(data)
    for link_ in actor.get_links('OA7') + actor.get_links('OA7', True):
        if actor.id == link_.domain.id:
            type_ = link_.type.get_name_directed() if link_.type else ''
            related = link_.range
        else:
            type_ = link_.type.get_name_directed(True) if link_.type else ''
            related = link_.domain
        data = ([type_, link(related), link_.first, link_.last, truncate_string(link_.description)])
        if is_authorized('editor'):
            update_url = url_for('relation_update', id_=link_.id, origin_id=actor.id)
            unlink_url = url_for('link_delete', id_=link_.id, origin_id=actor.id) + '#tab-relation'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
            data.append(display_remove_link(unlink_url, related.name))
        tables['relation']['data'].append(data)
    for link_ in actor.get_links('P107', True):
        data = ([link(link_.domain),
                 link_.type.name if link_.type else '',
                 link_.first,
                 link_.last,
                 truncate_string(link_.description)])
        if is_authorized('editor'):
            update_url = url_for('member_update', id_=link_.id, origin_id=actor.id)
            unlink_url = url_for('link_delete', id_=link_.id, origin_id=actor.id) + '#tab-member-of'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
            data.append(display_remove_link(unlink_url, link_.domain.name))
        tables['member_of']['data'].append(data)
    if actor.class_.code in app.config['CLASS_CODES']['group']:
        tables['member'] = {'id': 'member', 'data': [],
                            'header': ['member', 'function', 'first', 'last', 'description']}
        for link_ in actor.get_links('P107'):
            data = ([link(link_.range),
                     link_.type.name if link_.type else '',
                     link_.first,
                     link_.last,
                     truncate_string(link_.description)])
            if is_authorized('editor'):
                update_url = url_for('member_update', id_=link_.id, origin_id=actor.id)
                unlink_url = url_for('link_delete', id_=link_.id,
                                     origin_id=actor.id) + '#tab-member'
                data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
                data.append(display_remove_link(unlink_url, link_.range.name))
            tables['member']['data'].append(data)
    gis_data = GisMapper.get_all(objects) if objects else None
    if gis_data and gis_data['gisPointSelected'] == '[]':
        gis_data = None
    return render_template('actor/view.html', actor=actor, tables=tables, gis_data=gis_data,
                           profile_image_id=profile_image_id)
Beispiel #17
0
def actor_view(id_, unlink_id=None):
    actor = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    actor.set_dates()
    object_ids = []
    info = get_entity_data(actor)
    residence = actor.get_linked_entity('P74')
    if residence:
        object_ = residence.get_linked_entity('P53', True)
        object_ids.append(object_.id)
        info.append((uc_first(_('residence')), link(object_)))
    first = actor.get_linked_entity('OA8')
    if first:
        object_ = first.get_linked_entity('P53', True)
        object_ids.append(object_.id)
        info.append((uc_first(_('appears first')), link(object_)))
    last = actor.get_linked_entity('OA9')
    if last:
        object_ = last.get_linked_entity('P53', True)
        object_ids.append(object_.id)
        info.append((uc_first(_('appears last')), link(object_)))
    tables = {
        'info': info,
        'file': {
            'id': 'files',
            'data': [],
            'header': app.config['TABLE_HEADERS']['file']
        },
        'source': {
            'id': 'source',
            'data': [],
            'header': app.config['TABLE_HEADERS']['source']
        },
        'reference': {
            'id': 'reference',
            'data': [],
            'header': app.config['TABLE_HEADERS']['reference'] + ['pages']
        },
        'event': {
            'id':
            'event',
            'data': [],
            'header':
            ['event', 'class', 'involvement', 'first', 'last', 'description']
        },
        'relation': {
            'id': 'relation',
            'data': [],
            'sort': 'sortList:[[0,0]]',
            'header': ['relation', 'actor', 'first', 'last', 'description']
        },
        'member_of': {
            'id': 'member_of',
            'data': [],
            'header':
            ['member of', 'function', 'first', 'last', 'description']
        }
    }
    for link_ in actor.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        view_name = get_view_name(link_.domain)
        if view_name not in ['source', 'file']:
            data.append(truncate_string(link_.description))
            if is_authorized('editor'):
                update_url = url_for('reference_link_update',
                                     link_id=link_.id,
                                     origin_id=actor.id)
                data.append('<a href="' + update_url + '">' +
                            uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            unlink = url_for('actor_view', id_=actor.id,
                             unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink, link_.domain.name))
        tables[view_name]['data'].append(data)
    for link_ in actor.get_links(['P11', 'P14', 'P22', 'P23'], True):
        event = link_.domain
        first = link_.first
        place = event.get_linked_entity('P7')
        if place:
            object_ids.append(place.get_linked_entity('P53', True).id)
        if not link_.first and event.first:
            first = '<span class="inactive" style="float:right">' + str(
                event.first) + '</span>'
        last = link_.last
        if not link_.last and event.last:
            last = '<span class="inactive" style="float:right">' + str(
                event.last) + '</span>'
        data = ([
            link(event), g.classes[event.class_.code].name,
            link_.type.name if link_.type else '', first, last,
            truncate_string(link_.description)
        ])
        if is_authorized('editor'):
            update_url = url_for('involvement_update',
                                 id_=link_.id,
                                 origin_id=actor.id)
            unlink_url = url_for(
                'actor_view', id_=actor.id, unlink_id=link_.id) + '#tab-event'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables['event']['data'].append(data)
    for link_ in actor.get_links('OA7') + actor.get_links('OA7', True):
        if actor.id == link_.domain.id:
            type_ = link_.type.get_name_directed() if link_.type else ''
            related = link_.range
        else:
            type_ = link_.type.get_name_directed(True) if link_.type else ''
            related = link_.domain
        data = ([
            type_,
            link(related), link_.first, link_.last,
            truncate_string(link_.description)
        ])
        if is_authorized('editor'):
            update_url = url_for('relation_update',
                                 id_=link_.id,
                                 origin_id=actor.id)
            unlink_url = url_for('actor_view',
                                 id_=actor.id,
                                 unlink_id=link_.id) + '#tab-relation'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            data.append(display_remove_link(unlink_url, related.name))
        tables['relation']['data'].append(data)
    for link_ in actor.get_links('P107', True):
        data = ([
            link(link_.domain), link_.type.name if link_.type else '',
            link_.first, link_.last,
            truncate_string(link_.description)
        ])
        if is_authorized('editor'):
            update_url = url_for('member_update',
                                 id_=link_.id,
                                 origin_id=actor.id)
            unlink_url = url_for('actor_view',
                                 id_=actor.id,
                                 unlink_id=link_.id) + '#tab-member-of'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            data.append(display_remove_link(unlink_url, link_.domain.name))
        tables['member_of']['data'].append(data)
    if actor.class_.code in app.config['CLASS_CODES']['group']:
        tables['member'] = {
            'id': 'member',
            'header': ['member', 'function', 'first', 'last', 'description'],
            'data': []
        }
        for link_ in actor.get_links('P107'):
            data = ([
                link(link_.range), link_.type.name if link_.type else '',
                link_.first, link_.last,
                truncate_string(link_.description)
            ])
            if is_authorized('editor'):
                update_url = url_for('member_update',
                                     id_=link_.id,
                                     origin_id=actor.id)
                unlink_url = url_for('actor_view',
                                     id_=actor.id,
                                     unlink_id=link_.id) + '#tab-member'
                data.append('<a href="' + update_url + '">' +
                            uc_first(_('edit')) + '</a>')
                data.append(display_remove_link(unlink_url, link_.range.name))
            tables['member']['data'].append(data)
    gis_data = GisMapper.get_all(object_ids) if object_ids else None
    if gis_data and gis_data['gisPointSelected'] == '[]':
        gis_data = None
    return render_template('actor/view.html',
                           actor=actor,
                           tables=tables,
                           gis_data=gis_data)
Beispiel #18
0
def place_view(id_: int) -> str:
    object_ = EntityMapper.get_by_id(id_, nodes=True, aliases=True)
    object_.note = UserMapper.get_note(object_)
    location = object_.get_linked_entity('P53', nodes=True)
    tables = {
        'info':
        get_entity_data(object_, location),
        'file':
        Table(Table.HEADERS['file'] + [_('main image')]),
        'source':
        Table(Table.HEADERS['source']),
        'event':
        Table(Table.HEADERS['event'],
              defs='[{className: "dt-body-right", targets: [3,4]}]'),
        'reference':
        Table(Table.HEADERS['reference'] + ['page / link text']),
        'actor':
        Table([_('actor'),
               _('property'),
               _('class'),
               _('first'),
               _('last')])
    }
    if object_.system_type == 'place':
        tables['feature'] = Table(Table.HEADERS['place'] + [_('description')])
    if object_.system_type == 'feature':
        tables['stratigraphic-unit'] = Table(Table.HEADERS['place'] +
                                             [_('description')])
    if object_.system_type == 'stratigraphic unit':
        tables['find'] = Table(Table.HEADERS['place'] + [_('description')])
    profile_image_id = object_.get_profile_image_id()
    overlays = None
    if current_user.settings['module_map_overlay']:
        overlays = OverlayMapper.get_by_object(object_)
        if is_authorized('editor'):
            tables['file'].header.append(uc_first(_('overlay')))

    for link_ in object_.get_links('P67', inverse=True):
        domain = link_.domain
        data = get_base_table_data(domain)
        if domain.view_name == 'file':
            extension = data[3].replace('.', '')
            data.append(
                get_profile_image_table_link(domain, object_, extension,
                                             profile_image_id))
            if not profile_image_id and extension in app.config[
                    'DISPLAY_FILE_EXTENSIONS']:
                profile_image_id = domain.id
            if is_authorized(
                    'editor') and current_user.settings['module_map_overlay']:
                if extension in app.config['DISPLAY_FILE_EXTENSIONS']:
                    if domain.id in overlays:
                        url = url_for('overlay_update',
                                      id_=overlays[domain.id].id)
                        data.append('<a href="' + url + '">' +
                                    uc_first(_('edit')) + '</a>')
                    else:
                        url = url_for('overlay_insert',
                                      image_id=domain.id,
                                      place_id=object_.id,
                                      link_id=link_.id)
                        data.append('<a href="' + url + '">' +
                                    uc_first(_('add')) + '</a>')
                else:  # pragma: no cover
                    data.append('')
        if domain.view_name not in ['source', 'file']:
            data.append(truncate_string(link_.description))
            if domain.system_type.startswith('external reference'):
                object_.external_references.append(link_)
            if is_authorized(
                    'contributor'
            ) and domain.system_type != 'external reference geonames':
                url = url_for('reference_link_update',
                              link_id=link_.id,
                              origin_id=object_.id)
                data.append('<a href="' + url + '">' + uc_first(_('edit')) +
                            '</a>')
            else:
                data.append('')
        if is_authorized('contributor'):
            url = url_for('link_delete', id_=link_.id, origin_id=object_.id)
            data.append(
                display_remove_link(url + '#tab-' + domain.view_name,
                                    domain.name))
        tables[domain.view_name].rows.append(data)
    event_ids = []  # Keep track of already inserted events to prevent doubles
    for event in location.get_linked_entities(['P7', 'P26', 'P27'],
                                              inverse=True):
        tables['event'].rows.append(get_base_table_data(event))
        event_ids.append(event.id)
    for event in object_.get_linked_entities(['P24'], inverse=True):
        if event.id not in event_ids:  # Don't add again if already in table
            tables['event'].rows.append(get_base_table_data(event))
    has_subunits = False
    for entity in object_.get_linked_entities('P46', nodes=True):
        has_subunits = True
        data = get_base_table_data(entity)
        data.append(truncate_string(entity.description))
        tables[entity.system_type.replace(' ', '-')].rows.append(data)
    for link_ in location.get_links(['P74', 'OA8', 'OA9'], inverse=True):
        actor = EntityMapper.get_by_id(link_.domain.id)
        tables['actor'].rows.append([
            link(actor), g.properties[link_.property.code].name,
            actor.class_.name, actor.first, actor.last
        ])
    gis_data = GisMapper.get_all(object_) if location else None
    if gis_data['gisPointSelected'] == '[]' and gis_data['gisPolygonSelected'] == '[]' \
            and gis_data['gisLineSelected'] == '[]':
        gis_data = None
    place = None
    feature = None
    stratigraphic_unit = None
    if object_.system_type == 'find':
        stratigraphic_unit = object_.get_linked_entity('P46', True)
        feature = stratigraphic_unit.get_linked_entity('P46', True)
        place = feature.get_linked_entity('P46', True)
    elif object_.system_type == 'stratigraphic unit':
        feature = object_.get_linked_entity('P46', True)
        place = feature.get_linked_entity('P46', True)
    elif object_.system_type == 'feature':
        place = object_.get_linked_entity('P46', True)
    return render_template('place/view.html',
                           object_=object_,
                           tables=tables,
                           gis_data=gis_data,
                           place=place,
                           feature=feature,
                           stratigraphic_unit=stratigraphic_unit,
                           has_subunits=has_subunits,
                           profile_image_id=profile_image_id,
                           overlays=overlays)
Beispiel #19
0
def source_view(id_: int) -> str:
    source = EntityMapper.get_by_id(id_, nodes=True)
    source.note = UserMapper.get_note(source)
    tables = {
        'info': get_entity_data(source),
        'text': Table(['text', 'type', 'content']),
        'file': Table(Table.HEADERS['file'] + [_('main image')]),
        'reference': Table(Table.HEADERS['reference'] + ['page'])
    }
    for text in source.get_linked_entities('P73', nodes=True):
        tables['text'].rows.append([
            link(text),
            next(iter(text.nodes)).name if text.nodes else '',
            truncate_string(text.description)
        ])
    for name in [
            'actor', 'event', 'place', 'feature', 'stratigraphic-unit', 'find'
    ]:
        tables[name] = Table(Table.HEADERS[name])
    tables['actor'].defs = '[{className: "dt-body-right", targets: [2,3]}]'
    tables['event'].defs = '[{className: "dt-body-right", targets: [3,4]}]'
    tables['place'].defs = '[{className: "dt-body-right", targets: [2,3]}]'
    for link_ in source.get_links('P67'):
        range_ = link_.range
        data = get_base_table_data(range_)
        if is_authorized('contributor'):
            url = url_for('link_delete', id_=link_.id, origin_id=source.id)
            data.append(
                display_remove_link(url + '#tab-' + range_.table_name,
                                    range_.name))
        tables[range_.table_name].rows.append(data)
    profile_image_id = source.get_profile_image_id()
    for link_ in source.get_links(['P67'], True):
        domain = link_.domain
        data = get_base_table_data(domain)
        if domain.view_name == 'file':  # pragma: no cover
            extension = data[3].replace('.', '')
            data.append(
                get_profile_image_table_link(domain, source, extension,
                                             profile_image_id))
            if not profile_image_id and extension in app.config[
                    'DISPLAY_FILE_EXTENSIONS']:
                profile_image_id = domain.id
        if domain.view_name not in ['file']:
            data.append(link_.description)
            if domain.system_type == 'external reference':
                source.external_references.append(link_)
            if is_authorized('contributor'):
                url = url_for('reference_link_update',
                              link_id=link_.id,
                              origin_id=source.id)
                data.append('<a href="' + url + '">' + uc_first(_('edit')) +
                            '</a>')
        if is_authorized('contributor'):
            url = url_for('link_delete', id_=link_.id, origin_id=source.id)
            data.append(
                display_remove_link(url + '#tab-' + domain.view_name,
                                    domain.name))
        tables[domain.view_name].rows.append(data)
    return render_template('source/view.html',
                           source=source,
                           tables=tables,
                           profile_image_id=profile_image_id)
Beispiel #20
0
def entity_view(id_: int) -> Union[str, Response]:
    if id_ in g.nodes:  # Nodes have their own view
        entity = g.nodes[id_]
        if not entity.root:
            if entity.class_.name == 'administrative_unit':
                tab_hash = '#menu-tab-places_collapse-'
            elif entity.standard:
                tab_hash = '#menu-tab-standard_collapse-'
            elif entity.value_type:
                tab_hash = '#menu-tab-value_collapse-'
            else:
                tab_hash = '#menu-tab-custom_collapse-'
            return redirect(f"{url_for('node_index')}{tab_hash}{id_}")
    elif id_ in g.reference_systems:
        entity = g.reference_systems[id_]
    else:
        entity = Entity.get_by_id(id_, nodes=True, aliases=True)
        if not entity.class_.view:
            flash(_("This entity can't be viewed directly."), 'error')
            abort(400)

    event_links = None  # Needed for actor
    overlays = None  # Needed for place
    tabs = {'info': Tab('info')}
    if isinstance(entity, Node):
        tabs['subs'] = Tab('subs', entity=entity)
        tabs['entities'] = Tab('entities', entity=entity)
        root = g.nodes[entity.root[-1]] if entity.root else None
        if root and root.value_type:  # pragma: no cover
            tabs['entities'].table.header = [
                _('name'), _('value'),
                _('class'), _('info')
            ]
        for item in entity.get_linked_entities(['P2', 'P89'],
                                               inverse=True,
                                               nodes=True):
            if item.class_.name in ['location', 'reference_system']:
                continue  # pragma: no cover
            if item.class_.name == 'object_location':  # pragma: no cover
                item = item.get_linked_entity_safe('P53', inverse=True)
            data = [link(item)]
            if root and root.value_type:  # pragma: no cover
                data.append(format_number(item.nodes[entity]))
            data.append(item.class_.label)
            data.append(item.description)
            tabs['entities'].table.rows.append(data)
        for sub_id in entity.subs:
            sub = g.nodes[sub_id]
            tabs['subs'].table.rows.append(
                [link(sub), sub.count, sub.description])
        if not tabs['entities'].table.rows:
            # If no entities available get links with this type_id
            tabs['entities'].table.header = [_('domain'), _('range')]
            for row in Link.get_entities_by_node(entity):
                tabs['entities'].table.rows.append([
                    link(Entity.get_by_id(row['domain_id'])),
                    link(Entity.get_by_id(row['range_id']))
                ])
    elif isinstance(entity, ReferenceSystem):
        for form_id, form in entity.get_forms().items():
            tabs[form['name']] = Tab(form['name'], entity=entity)
            tabs[form['name']].table = \
                Table([_('entity'), 'id', _('precision')])
        for link_ in entity.get_links('P67'):
            name = link_.description
            if entity.resolver_url:
                name = \
                    f'<a href="{entity.resolver_url + name}"' \
                    f' target="_blank" rel="noopener noreferrer">{name}</a>'
            tab_name = link_.range.class_.name
            tabs[tab_name].table.rows.append(
                [link(link_.range), name, link_.type.name])
        for form_id, form in entity.get_forms().items():
            tabs[form['name']].buttons = []
            if not tabs[form['name']].table.rows and is_authorized('manager'):
                tabs[form['name']].buttons = [
                    button(
                        _('remove'),
                        url_for('reference_system_remove_form',
                                system_id=entity.id,
                                form_id=form_id))
                ]
    elif entity.class_.view == 'actor':
        for name in [
                'source', 'event', 'relation', 'member_of', 'member',
                'artifact'
        ]:
            tabs[name] = Tab(name, entity=entity)
        event_links = entity.get_links(['P11', 'P14', 'P22', 'P23', 'P25'],
                                       True)
        for link_ in event_links:
            event = link_.domain
            places = event.get_linked_entities(['P7', 'P26', 'P27'])
            link_.object_ = None  # Needed for first/last appearance
            for place in places:
                object_ = place.get_linked_entity_safe('P53', True)
                entity.linked_places.append(object_)
                link_.object_ = object_
            first = link_.first
            if not link_.first and event.first:
                first = f'<span class="inactive">{event.first}</span>'
            last = link_.last
            if not link_.last and event.last:
                last = f'<span class="inactive">{event.last}</span>'
            data = [
                link(event), event.class_.label,
                _('moved') if link_.property.code == 'P25' else link(
                    link_.type), first, last, link_.description
            ]
            if link_.property.code == 'P25':
                data += ['']
            else:
                add_edit_link(
                    data,
                    url_for('involvement_update',
                            id_=link_.id,
                            origin_id=entity.id))
            add_remove_link(data, link_.domain.name, link_, entity, 'event')
            tabs['event'].table.rows.append(data)
        for link_ in entity.get_links('OA7') + entity.get_links('OA7', True):
            type_ = ''
            if entity.id == link_.domain.id:
                related = link_.range
                if link_.type:
                    type_ = link(link_.type.get_name_directed(),
                                 url_for('entity_view', id_=link_.type.id))
            else:
                related = link_.domain
                if link_.type:
                    type_ = link(link_.type.get_name_directed(True),
                                 url_for('entity_view', id_=link_.type.id))
            data = [
                type_,
                link(related), link_.first, link_.last, link_.description
            ]
            add_edit_link(
                data,
                url_for('relation_update', id_=link_.id, origin_id=entity.id))
            add_remove_link(data, related.name, link_, entity, 'relation')
            tabs['relation'].table.rows.append(data)
        for link_ in entity.get_links('P107', True):
            data = [
                link(link_.domain),
                link(link_.type), link_.first, link_.last, link_.description
            ]
            add_edit_link(
                data,
                url_for('member_update', id_=link_.id, origin_id=entity.id))
            add_remove_link(data, link_.domain.name, link_, entity,
                            'member-of')
            tabs['member_of'].table.rows.append(data)
        if entity.class_.name != 'group':
            del tabs['member']
        else:
            for link_ in entity.get_links('P107'):
                data = [
                    link(link_.range),
                    link(link_.type), link_.first, link_.last,
                    link_.description
                ]
                add_edit_link(
                    data,
                    url_for('member_update', id_=link_.id,
                            origin_id=entity.id))
                add_remove_link(data, link_.range.name, link_, entity,
                                'member')
                tabs['member'].table.rows.append(data)
        for link_ in entity.get_links('P52', True):
            data = [
                link(link_.domain), link_.domain.class_.label,
                link(link_.domain.standard_type), link_.domain.first,
                link_.domain.last, link_.domain.description
            ]
            tabs['artifact'].table.rows.append(data)
    elif entity.class_.view == 'artifact':
        tabs['source'] = Tab('source', entity=entity)
    elif entity.class_.view == 'event':
        for name in ['subs', 'source', 'actor']:
            tabs[name] = Tab(name, entity=entity)
        for sub_event in entity.get_linked_entities('P117',
                                                    inverse=True,
                                                    nodes=True):
            tabs['subs'].table.rows.append(get_base_table_data(sub_event))
        tabs['actor'].table.header.insert(5, _('activity'))  # Activity column
        for link_ in entity.get_links(['P11', 'P14', 'P22', 'P23']):
            first = link_.first
            if not link_.first and entity.first:
                first = f'<span class="inactive">{entity.first}</span>'
            last = link_.last
            if not link_.last and entity.last:
                last = f'<span class="inactive">{entity.last}</span>'
            data = [
                link(link_.range), link_.range.class_.label,
                link_.type.name if link_.type else '', first, last,
                g.properties[link_.property.code].name_inverse,
                link_.description
            ]
            add_edit_link(
                data,
                url_for('involvement_update',
                        id_=link_.id,
                        origin_id=entity.id))
            add_remove_link(data, link_.range.name, link_, entity, 'actor')
            tabs['actor'].table.rows.append(data)
        entity.linked_places = [
            location.get_linked_entity_safe('P53', True)
            for location in entity.get_linked_entities(['P7', 'P26', 'P27'])
        ]
    elif entity.class_.view == 'file':
        for name in [
                'source', 'event', 'actor', 'place', 'feature',
                'stratigraphic_unit', 'artifact', 'human_remains', 'reference',
                'type'
        ]:
            tabs[name] = Tab(name, entity=entity)
        entity.image_id = entity.id if get_file_path(entity.id) else None
        for link_ in entity.get_links('P67'):
            range_ = link_.range
            data = get_base_table_data(range_)
            add_remove_link(data, range_.name, link_, entity,
                            range_.class_.name)
            tabs[range_.class_.view].table.rows.append(data)
        for link_ in entity.get_links('P67', True):
            data = get_base_table_data(link_.domain)
            data.append(link_.description)
            add_edit_link(
                data,
                url_for('reference_link_update',
                        link_id=link_.id,
                        origin_id=entity.id))
            add_remove_link(data, link_.domain.name, link_, entity,
                            'reference')
            tabs['reference'].table.rows.append(data)
    elif entity.class_.view == 'place':
        tabs['source'] = Tab('source', entity=entity)
        if entity.class_.name == 'place':
            tabs['event'] = Tab('event', entity=entity)
        tabs['reference'] = Tab('reference', entity=entity)
        if entity.class_.name == 'place':
            tabs['actor'] = Tab('actor', entity=entity)
            tabs['feature'] = Tab('feature', entity=entity)
        elif entity.class_.name == 'feature':
            tabs['stratigraphic_unit'] = Tab('stratigraphic_unit',
                                             entity=entity)
        elif entity.class_.name == 'stratigraphic_unit':
            tabs['find'] = Tab('find', entity=entity)
            tabs['human_remains'] = Tab('human_remains', entity=entity)
        entity.location = entity.get_linked_entity_safe('P53', nodes=True)
        event_ids = []  # Keep track of inserted events to prevent doubles
        for event in entity.location.get_linked_entities(['P7', 'P26', 'P27'],
                                                         inverse=True):
            tabs['event'].table.rows.append(get_base_table_data(event))
            event_ids.append(event.id)
        for event in entity.get_linked_entities('P24', inverse=True):
            if event.id not in event_ids:  # Don't add again if already in table
                tabs['event'].table.rows.append(get_base_table_data(event))
        if 'actor' in tabs:
            for link_ in entity.location.get_links(['P74', 'OA8', 'OA9'],
                                                   inverse=True):
                actor = Entity.get_by_id(link_.domain.id)
                tabs['actor'].table.rows.append([
                    link(actor), g.properties[link_.property.code].name,
                    actor.class_.name, actor.first, actor.last,
                    actor.description
                ])
    elif entity.class_.view == 'reference':
        for name in [
                'source', 'event', 'actor', 'place', 'feature',
                'stratigraphic_unit', 'human_remains', 'artifact', 'file'
        ]:
            tabs[name] = Tab(name, entity=entity)
        for link_ in entity.get_links('P67'):
            range_ = link_.range
            data = get_base_table_data(range_)
            data.append(link_.description)
            add_edit_link(
                data,
                url_for('reference_link_update',
                        link_id=link_.id,
                        origin_id=entity.id))
            add_remove_link(data, range_.name, link_, entity,
                            range_.class_.name)
            tabs[range_.class_.view].table.rows.append(data)
    elif entity.class_.view == 'source':
        for name in [
                'actor', 'artifact', 'feature', 'event', 'human_remains',
                'place', 'stratigraphic_unit', 'text'
        ]:
            tabs[name] = Tab(name, entity=entity)
        for text in entity.get_linked_entities('P73', nodes=True):
            tabs['text'].table.rows.append([
                link(text),
                next(iter(text.nodes)).name if text.nodes else '',
                text.description
            ])
        for link_ in entity.get_links('P67'):
            range_ = link_.range
            data = get_base_table_data(range_)
            add_remove_link(data, range_.name, link_, entity,
                            range_.class_.name)
            tabs[range_.class_.view].table.rows.append(data)

    if entity.class_.view in [
            'actor', 'artifact', 'event', 'place', 'source', 'type'
    ]:
        if entity.class_.view != 'reference' and not isinstance(entity, Node):
            tabs['reference'] = Tab('reference', entity=entity)
        if entity.class_.view == 'artifact':
            tabs['event'] = Tab('event', entity=entity)
            for link_ in entity.get_links('P25', True):
                data = get_base_table_data(link_.domain)
                tabs['event'].table.rows.append(data)
        tabs['file'] = Tab('file', entity=entity)
        entity.image_id = entity.get_profile_image_id()
        if entity.class_.view == 'place' and is_authorized('editor') and \
                current_user.settings['module_map_overlay']:
            tabs['file'].table.header.append(uc_first(_('overlay')))
        for link_ in entity.get_links('P67', inverse=True):
            domain = link_.domain
            data = get_base_table_data(domain)
            if domain.class_.view == 'file':  # pragma: no cover
                extension = data[3]
                data.append(
                    get_profile_image_table_link(domain, entity, extension,
                                                 entity.image_id))
                if not entity.image_id \
                        and extension in app.config['DISPLAY_FILE_EXTENSIONS']:
                    entity.image_id = domain.id
                if entity.class_.view == 'place' \
                        and is_authorized('editor') \
                        and current_user.settings['module_map_overlay']:
                    overlays = Overlay.get_by_object(entity)
                    if extension in app.config['DISPLAY_FILE_EXTENSIONS']:
                        if domain.id in overlays:
                            add_edit_link(
                                data,
                                url_for('overlay_update',
                                        id_=overlays[domain.id].id))
                        else:
                            data.append(
                                link(
                                    _('link'),
                                    url_for('overlay_insert',
                                            image_id=domain.id,
                                            place_id=entity.id,
                                            link_id=link_.id)))
                    else:  # pragma: no cover
                        data.append('')
            if domain.class_.view not in ['source', 'file']:
                data.append(link_.description)
                add_edit_link(
                    data,
                    url_for('reference_link_update',
                            link_id=link_.id,
                            origin_id=entity.id))
                if domain.class_.view == 'reference_system':
                    entity.reference_systems.append(link_)
                    continue
            add_remove_link(data, domain.name, link_, entity,
                            domain.class_.view)
            tabs[domain.class_.view].table.rows.append(data)

    structure = None  # Needed for place
    gis_data = None  # Needed for place
    if entity.class_.view in ['artifact', 'place']:
        structure = get_structure(entity)
        if structure:
            for item in structure['subunits']:
                tabs[item.class_.name].table.rows.append(
                    get_base_table_data(item))
        gis_data = Gis.get_all([entity], structure)
        if gis_data['gisPointSelected'] == '[]' \
                and gis_data['gisPolygonSelected'] == '[]' \
                and gis_data['gisLineSelected'] == '[]' \
                and (not structure or not structure['super_id']):
            gis_data = {}

    if not gis_data:
        gis_data = Gis.get_all(entity.linked_places) \
            if entity.linked_places else None
    entity.info_data = get_entity_data(entity, event_links=event_links)
    tabs['note'] = Tab('note', entity=entity)
    for note in current_user.get_notes_by_entity_id(entity.id):
        data = [
            format_date(note['created']),
            uc_first(_('public'))
            if note['public'] else uc_first(_('private')),
            link(User.get_by_id(note['user_id'])), note['text'],
            f'<a href="{url_for("note_view", id_=note["id"])}">'
            f'{uc_first(_("view"))}</a>'
        ]
        tabs['note'].table.rows.append(data)
    if 'file' in tabs and current_user.settings['table_show_icons'] and \
            session['settings']['image_processing']:
        tabs['file'].table.header.insert(1, uc_first(_('icon')))
        for row in tabs['file'].table.rows:
            row.insert(
                1,
                file_preview(
                    int(row[0].replace('<a href="/entity/',
                                       '').split('"')[0])))
    tabs['info'].content = render_template(
        'entity/view.html',
        buttons=add_buttons(entity),
        entity=entity,
        gis_data=gis_data,
        structure=structure,  # Needed for place views
        overlays=overlays,  # Needed for place views
        title=entity.name)
    return render_template('tabs.html',
                           tabs=tabs,
                           gis_data=gis_data,
                           crumbs=add_crumbs(entity, structure),
                           entity=entity)
Beispiel #21
0
def event_view(id_, unlink_id=None):
    event = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    event.set_dates()
    tables = {
        'info': get_entity_data(event),
        'file': {
            'id': 'files',
            'data': [],
            'header': app.config['TABLE_HEADERS']['file']
        },
        'subs': {
            'id': 'sub-event',
            'data': [],
            'header': app.config['TABLE_HEADERS']['event']
        },
        'actor': {
            'id':
            'actor',
            'data': [],
            'header':
            ['actor', 'class', 'involvement', 'first', 'last', 'description']
        },
        'source': {
            'id': 'source',
            'data': [],
            'header': app.config['TABLE_HEADERS']['source'] + ['description']
        },
        'reference': {
            'id': 'reference',
            'data': [],
            'header': app.config['TABLE_HEADERS']['reference'] + ['pages']
        }
    }
    for link_ in event.get_links(['P11', 'P14', 'P22', 'P23']):
        first = link_.first
        if not link_.first and event.first:
            first = '<span class="inactive" style="float:right">' + str(
                event.first) + '</span>'
        last = link_.last
        if not link_.last and event.last:
            last = '<span class="inactive" style="float:right">' + str(
                event.last) + '</span>'
        data = ([
            link(link_.range), g.classes[link_.range.class_.code].name,
            link_.type.name if link_.type else '', first, last,
            truncate_string(link_.description)
        ])
        if is_authorized('editor'):
            unlink_url = url_for(
                'event_view', id_=event.id, unlink_id=link_.id) + '#tab-actor'
            update_url = url_for('involvement_update',
                                 id_=link_.id,
                                 origin_id=event.id)
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables['actor']['data'].append(data)
    for link_ in event.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        view_name = get_view_name(link_.domain)
        if view_name not in ['source', 'file']:
            data.append(truncate_string(link_.description))
            if is_authorized('editor'):
                update_url = url_for('reference_link_update',
                                     link_id=link_.id,
                                     origin_id=event.id)
                data.append('<a href="' + update_url + '">' +
                            uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            unlink = url_for('event_view', id_=event.id,
                             unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink, link_.domain.name))
        tables[view_name]['data'].append(data)
    for sub_event in event.get_linked_entities('P117', True):
        tables['subs']['data'].append(get_base_table_data(sub_event))
    return render_template('event/view.html', event=event, tables=tables)