Пример #1
0
def get_subunits(
        entity: Entity,
        children: list[Entity],
        links: list[Link],
        links_inverse: list[Link],
        root: Entity,
        latest_mod_rec: datetime,
        type_links_inverse: list[Link],
        parser: dict[str, Any]) -> dict[str, Any]:
    return replace_empty_list_values_in_dict_with_none({
        'id': entity.id,
        'rootId': root.id,
        'parentId':
            entity.get_linked_entity_safe('P46', inverse=True).id
            if entity.id != root.id else None,
        'openatlasClassName': entity.class_.name,
        'crmClass': entity.cidoc_class.code,
        'created': str(entity.created),
        'modified': str(entity.modified),
        'latestModRec': latest_mod_rec,
        'geometry': get_geometries_thanados(entity, links, parser),
        'children': get_children(children, parser) if children else None,
        'properties': get_properties(
            entity,
            links,
            links_inverse,
            type_links_inverse,
            parser)})
Пример #2
0
    def get_by_object(object_: Entity) -> Dict[int, Overlay]:
        if not app.config['IS_UNIT_TEST'] and not current_user.settings['module_map_overlay']:
            return {}  # pragma: no cover - tests have no direct access to user settings

        ids = [object_.id]
        # Get overlays of parents
        if object_.class_.name == 'find':
            stratigraphic_unit = object_.get_linked_entity_safe('P46', True)
            ids.append(stratigraphic_unit.id)
            feature = stratigraphic_unit.get_linked_entity_safe('P46', True)
            ids.append(feature.id)
            ids.append(feature.get_linked_entity_safe('P46', True).id)
        elif object_.class_.name == 'stratigraphic_unit':
            feature = object_.get_linked_entity_safe('P46', True)
            ids.append(feature.id)
            ids.append(feature.get_linked_entity_safe('P46', True).id)
        elif object_.class_.name == 'feature':
            ids.append(object_.get_linked_entity_safe('P46', True).id)
        return {row['image_id']: Overlay(row) for row in Db.get_by_object(ids)}
Пример #3
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
Пример #4
0
def get_place_info_for_update(entity: Entity) -> dict[str, Any]:
    if entity.class_.view not in ['artifact', 'place']:
        return {
            'structure': None,
            'gis_data': None,
            'overlays': None,
            'location': None}
    structure = get_structure(entity)
    return {
        'structure': structure,
        'gis_data': Gis.get_all([entity], structure),
        'overlays': Overlay.get_by_object(entity),
        'location': entity.get_linked_entity_safe('P53', types=True)}
    def get_by_object(object_: Entity) -> Dict[int, Overlay]:
        ids = [object_.id]

        # Get overlays of parents
        if object_.system_type == 'find':
            stratigraphic_unit = object_.get_linked_entity_safe('P46', True)
            ids.append(stratigraphic_unit.id)
            feature = stratigraphic_unit.get_linked_entity_safe('P46', True)
            ids.append(feature.id)
            ids.append(feature.get_linked_entity_safe('P46', True).id)
        elif object_.system_type == 'stratigraphic unit':
            feature = object_.get_linked_entity_safe('P46', True)
            ids.append(feature.id)
            ids.append(feature.get_linked_entity_safe('P46', True).id)
        elif object_.system_type == 'feature':
            ids.append(object_.get_linked_entity_safe('P46', True).id)

        sql = """
            SELECT o.id, o.place_id, o.image_id, o.bounding_box, i.name
            FROM web.map_overlay o
            JOIN model.entity i ON o.image_id = i.id
            WHERE o.place_id IN %(place_ids)s;"""
        g.execute(sql, {'place_ids': tuple(ids)})
        return {row.image_id: Overlay(row) for row in g.cursor.fetchall()}
Пример #6
0
def update_links(entity: Entity, form: FlaskForm, action: str,
                 origin: Optional[Entity]) -> None:
    if entity.class_.view in ['actor', 'event', 'place', 'artifact', 'type']:
        ReferenceSystem.update_links(form, entity)
    if entity.class_.view == 'actor':
        if action == 'update':
            entity.delete_links(['P74', 'OA8', 'OA9'])
        if form.residence.data:
            object_ = Entity.get_by_id(form.residence.data)
            entity.link('P74', object_.get_linked_entity_safe('P53'))
        if form.begins_in.data:
            object_ = Entity.get_by_id(form.begins_in.data)
            entity.link('OA8', object_.get_linked_entity_safe('P53'))
        if form.ends_in.data:
            object_ = Entity.get_by_id(form.ends_in.data)
            entity.link('OA9', object_.get_linked_entity_safe('P53'))
    if entity.class_.view == 'event':
        if action == 'update':
            entity.delete_links(['P7', 'P24', 'P25', 'P26', 'P27', 'P117'])
        if form.event.data:
            entity.link_string('P117', form.event.data)
        if hasattr(form, 'place') and form.place.data:
            entity.link(
                'P7', Link.get_linked_entity_safe(int(form.place.data), 'P53'))
        if entity.class_.name == 'acquisition' and form.given_place.data:
            entity.link_string('P24', form.given_place.data)
        if entity.class_.name == 'move':
            if form.artifact.data:  # Moved objects
                entity.link_string('P25', form.artifact.data)
            if form.person.data:  # Moved persons
                entity.link_string('P25', form.person.data)
            if form.place_from.data:  # Link place for move from
                linked_place = Link.get_linked_entity_safe(
                    int(form.place_from.data), 'P53')
                entity.link('P27', linked_place)
            if form.place_to.data:  # Link place for move to
                entity.link(
                    'P26',
                    Link.get_linked_entity_safe(int(form.place_to.data),
                                                'P53'))
    elif entity.class_.view in ['artifact', 'place']:
        location = entity.get_linked_entity_safe('P53')
        if action == 'update':
            Gis.delete_by_entity(location)
        location.update(form)
        Gis.insert(location, form)
    elif entity.class_.view == 'source' and not origin:
        if action == 'update':
            entity.delete_links(['P128'], inverse=True)
        if form.artifact.data:
            entity.link_string('P128', form.artifact.data, inverse=True)
    elif entity.class_.view == 'type':
        node = origin if isinstance(origin, Node) else entity
        root = g.nodes[node.root[-1]] if node.root else node
        super_id = g.nodes[node.root[0]] if node.root else node
        new_super_id = getattr(form, str(root.id)).data
        new_super = g.nodes[int(new_super_id)] if new_super_id else root
        if super_id != new_super.id:
            property_code = 'P127' if entity.class_.name == 'type' else 'P89'
            entity.delete_links([property_code])
            entity.link(property_code, new_super)