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)
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 #3
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)
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 #5
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)
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 #7
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 #8
0
def actor_view(id_: int) -> str:
    actor = EntityMapper.get_by_id(id_, nodes=True, aliases=True)
    actor.note = UserMapper.get_note(actor)
    info = []
    if actor.aliases:
        info.append(
            (uc_first(_('alias')), '<br />'.join(actor.aliases.values())))
    tables = {
        'info':
        info,
        'file':
        Table(Table.HEADERS['file'] + [_('main image')]),
        'source':
        Table(Table.HEADERS['source']),
        'reference':
        Table(Table.HEADERS['reference'] + ['page / link text']),
        'event':
        Table(
            ['event', 'class', 'involvement', 'first', 'last', 'description'],
            defs='[{className: "dt-body-right", targets: [3,4]}]'),
        'relation':
        Table(['relation', 'actor', 'first', 'last', 'description'],
              defs='[{className: "dt-body-right", targets: [2,3]}]'),
        'member_of':
        Table(['member of', 'function', 'first', 'last', 'description'],
              defs='[{className: "dt-body-right", targets: [2,3]}]')
    }
    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 domain.system_type == 'external reference':
                actor.external_references.append(link_)
            if is_authorized('contributor'):
                url = url_for('reference_link_update',
                              link_id=link_.id,
                              origin_id=actor.id)
                data.append('<a href="' + url + '">' + uc_first(_('edit')) +
                            '</a>')
        if is_authorized('contributor'):
            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].rows.append(data)

    # Todo: Performance - getting every place of every object for every event is very costly
    event_links = actor.get_links(['P11', 'P14', 'P22', 'P23', 'P25'], True)

    objects = []
    for link_ in event_links:
        event = link_.domain
        place = event.get_linked_entity('P7')
        link_.object_ = None
        if place:
            object_ = place.get_linked_entity('P53', True)
            objects.append(object_)
            link_.object_ = object_  # May be used later for first/last appearance info
        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(event), g.classes[event.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=actor.id)
            unlink_url = url_for(
                'link_delete', id_=link_.id, origin_id=actor.id) + '#tab-event'
            if link_.domain.class_.code != 'E9':
                data.append('<a href="' + update_url + '">' +
                            uc_first(_('edit')) + '</a>')
            else:
                data.append('')
            data.append(display_remove_link(unlink_url, link_.domain.name))
        tables['event'].rows.append(data)

    # Add info of dates and places
    begin_place = actor.get_linked_entity('OA8')
    begin_object = None
    if begin_place:
        begin_object = begin_place.get_linked_entity('P53', True)
        objects.append(begin_object)
    end_place = actor.get_linked_entity('OA9')
    end_object = None
    if end_place:
        end_object = end_place.get_linked_entity('P53', True)
        objects.append(end_object)
    label = uc_first(_('born') if actor.class_.code == 'E21' else _('begin'))
    info.append((label, format_entry_begin(actor, begin_object)))
    label = uc_first(_('died') if actor.class_.code == 'E21' else _('end'))
    info.append((label, format_entry_end(actor, end_object)))
    appears_first, appears_last = get_appearance(event_links)
    info.append((_('appears first'), appears_first))
    info.append((_('appears last'), appears_last))

    residence_place = actor.get_linked_entity('P74')
    if residence_place:
        residence_object = residence_place.get_linked_entity('P53', True)
        objects.append(residence_object)
        info.append((uc_first(_('residence')), link(residence_object)))
    add_type_data(actor, info)
    add_system_data(actor, info)

    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('contributor'):
            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'].rows.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('contributor'):
            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'].rows.append(data)
    if actor.class_.code in app.config['CLASS_CODES']['group']:
        tables['member'] = Table(
            ['member', 'function', 'first', 'last', 'description'],
            defs='[{className: "dt-body-right", targets: [2,3]}]')
        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('contributor'):
                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'].rows.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 #9
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)