From 581b0c97527208ecae81056002f40d3a3e8aab0e Mon Sep 17 00:00:00 2001 From: Bernhard Koschicek-Krombholz Date: Thu, 30 Jan 2025 12:16:59 +0100 Subject: [PATCH] added examples for annotation in lp --- openatlas/api/endpoints/parser.py | 16 +++++++++++----- openatlas/api/resources/templates.py | 5 ++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/openatlas/api/endpoints/parser.py b/openatlas/api/endpoints/parser.py index 2a7854b0f..7863089c2 100644 --- a/openatlas/api/endpoints/parser.py +++ b/openatlas/api/endpoints/parser.py @@ -25,7 +25,7 @@ flatten_list_and_remove_duplicates, get_geometric_collection, get_geoms_dict, get_location_link, get_reference_systems, replace_empty_list_values_in_dict_with_none) -from openatlas.display.util import description +from openatlas.models.annotation import AnnotationText from openatlas.models.entity import Entity, Link from openatlas.models.gis import Gis @@ -191,10 +191,16 @@ def get_geom(self, entity: Entity, ) -> list[Any]: return [] def get_annotations(self, entity: Entity) -> list[dict[str, Any]]: - description_ = entity.description - if entity.cidoc_class == 'E33' and self.annotations == 'html': - description_ = entity.get_annotated_text() - return [{'value': description_}] if 'description' in self.show else None + description_ = {'value': entity.description} + if entity.cidoc_class.code == 'E33' and self.annotations == 'html': + description_['annotation_text'] = entity.get_annotated_text() + description_['annotations'] = [{ + 'source_id': a.source_id, + 'entity_id': a.entity_id, + 'link_start': a.link_start, + 'link_end': a.link_end, + 'text': a.text} for a in AnnotationText.get_by_source_id(entity.id)] + return [description_] if 'description' in self.show else None def get_linked_places_entity( self, diff --git a/openatlas/api/resources/templates.py b/openatlas/api/resources/templates.py index 6122813e3..b39e10b72 100644 --- a/openatlas/api/resources/templates.py +++ b/openatlas/api/resources/templates.py @@ -103,7 +103,10 @@ def linked_places_template(parser: Parser) -> dict[str, Type[String]]: 'earliest': fields.String, 'latest': fields.String, 'comment': fields.String} - description = {'value': fields.String} + description = { + 'value': fields.String, + 'annotation_text': fields.String, + 'annotations': fields.Raw} timespans = {'start': fields.Nested(start), 'end': fields.Nested(end)} when = {'timespans': fields.List(fields.Nested(timespans))} relations = {