Exemple #1
0
def add_tabs_for_event(entity: Entity) -> dict[str, Tab]:
    tabs = {}
    for name in ['subs', 'source', 'actor']:
        tabs[name] = Tab(name, entity=entity)
    for sub_event in entity.get_linked_entities(
            'P9',
            inverse=True,
            types=True):
        tabs['subs'].table.rows.append(get_base_table_data(sub_event))
    tabs['actor'].table.header.insert(5, _('activity'))
    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>'
        tabs['actor'].table.rows.append([
            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,
            edit_link(
                url_for('link_update', id_=link_.id, origin_id=entity.id)),
            remove_link(link_.range.name, link_, entity, 'actor')])
    entity.linked_places = [
        location.get_linked_entity_safe('P53', True) for location
        in entity.get_linked_entities(['P7', 'P26', 'P27'])]
    return tabs
Exemple #2
0
def add_buttons(entity: Entity, type_problem: bool = False) -> list[str]:
    if not is_authorized(entity.class_.write_access):
        return []  # pragma: no cover
    buttons = []
    if isinstance(entity, Type):
        if entity.root and entity.category != 'system':
            buttons.append(button(_('edit'), url_for('update', id_=entity.id)))
            buttons.append(display_delete_link(entity))
    elif isinstance(entity, ReferenceSystem):
        buttons.append(button(_('edit'), url_for('update', id_=entity.id)))
        if not entity.classes and not entity.system:
            buttons.append(display_delete_link(entity))
    elif entity.class_.name == 'source_translation':
        buttons.append(button(_('edit'), url_for('update', id_=entity.id)))
        buttons.append(display_delete_link(entity))
    else:
        if not type_problem:
            buttons.append(button(_('edit'), url_for('update', id_=entity.id)))
        if entity.class_.view != 'place' \
                or not entity.get_linked_entities('P46'):
            buttons.append(display_delete_link(entity))
    if entity.class_.name == 'stratigraphic_unit':
        buttons.append(
            button(_('tools'), url_for('anthropology_index', id_=entity.id)))
    return buttons
Exemple #3
0
def get_all_subunits_recursive(
        entity: Entity, data: list[dict[Entity, Any]]) -> list[dict[Any, Any]]:
    if entity.class_.name not in ['artifact', 'human_remains']:
        sub_entities = entity.get_linked_entities('P46', types=True)
        data[-1] = {entity: sub_entities if sub_entities else None}
        if sub_entities:
            for e in sub_entities:
                data.append({e: []})
        if sub_entities:
            for e in sub_entities:
                get_all_subunits_recursive(e, data)
    return data
Exemple #4
0
def add_tabs_for_place(entity: Entity) -> dict[str, Tab]:
    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['artifact'] = Tab('artifact', entity=entity)
        tabs['human_remains'] = Tab('human_remains', entity=entity)
    entity.location = entity.get_linked_entity_safe('P53', types=True)
    events = []  # Collect events to display actors
    event_ids = []  # Keep track of event ids to prevent event doubles
    for event in entity.location.get_linked_entities(
            ['P7', 'P26', 'P27'],
            inverse=True):
        events.append(event)
        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))
            events.append(event)
    if entity.class_.name == 'place':
        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])
        actor_ids = []
        for event in events:
            for actor in event.get_linked_entities(
                    ['P11', 'P14', 'P22', 'P23']):
                if actor.id in actor_ids:
                    continue  # pragma: no cover
                actor_ids.append(actor.id)
                tabs['actor'].table.rows.append([
                    link(actor),
                    f"{_('participated at an event')}",
                    event.class_.name, '', '', ''])
    return tabs
Exemple #5
0
def add_tabs_for_source(entity: Entity) -> dict[str, Tab]:
    tabs = {}
    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', types=True):
        tabs['text'].table.rows.append([
            link(text),
            next(iter(text.types)).name if text.types else '', text.description
        ])
    for link_ in entity.get_links('P67'):
        range_ = link_.range
        data = get_base_table_data(range_)
        data.append(remove_link(range_.name, link_, entity,
                                range_.class_.name))
        tabs[range_.class_.view].table.rows.append(data)
    return tabs
Exemple #6
0
def add_buttons(entity: Entity) -> List[str]:
    if not is_authorized(entity.class_.write_access):
        return []  # pragma: no cover
    buttons = []
    if isinstance(entity, Node):
        if entity.root and not g.nodes[entity.root[0]].locked:
            buttons.append(button(_('edit'), url_for('update', id_=entity.id)))
            if not entity.locked and entity.count < 1 and not entity.subs:
                buttons.append(display_delete_link(entity))
    elif isinstance(entity, ReferenceSystem):
        buttons.append(button(_('edit'), url_for('update', id_=entity.id)))
        if not entity.forms and not entity.system:
            buttons.append(display_delete_link(entity))
    elif entity.class_.name == 'source_translation':
        buttons.append(
            button(_('edit'), url_for('translation_update', id_=entity.id)))
        buttons.append(display_delete_link(entity))
    else:
        buttons.append(button(_('edit'), url_for('update', id_=entity.id)))
        if entity.class_.view != 'place' \
                or not entity.get_linked_entities('P46'):
            buttons.append(display_delete_link(entity))
    return buttons