Skip to content

Commit

Permalink
Merge branch 'develop' into feature/them_bones
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Feb 14, 2025
2 parents 8c27279 + 20dc1b4 commit 540d3cb
Show file tree
Hide file tree
Showing 38 changed files with 4,136 additions and 2,493 deletions.
13 changes: 12 additions & 1 deletion config/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
'lpx': 'application/ld+json',
'loud': 'application/ld+json',
'geojson': 'application/json',
'geojson-v2': 'application/json'}
'geojson-v2': 'application/json',
'presentation': 'application/json'}
API_FORMATS = RDF_FORMATS | JSON_FORMATS

LOGICAL_OPERATOR: list[str] = ['and', 'or']
Expand All @@ -53,3 +54,13 @@

# Used to connect to password protected Vocabs systems
VOCABS_PASS = ''

API_PRESENTATION_EXCLUDE_RELATION = [
'bone',
'file',
'type',
'type_tools'
'appellation',
'object_location',
'reference_system',
'administrative_unit']
2 changes: 1 addition & 1 deletion config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from config.database_versions import DATABASE_VERSIONS

VERSION = '8.10.0'
VERSION = '8.11.0'
DATABASE_VERSION = DATABASE_VERSIONS[0]
DEMO_MODE = False # If activated some options are disabled, login is prefilled
DEBUG = False
Expand Down
13 changes: 4 additions & 9 deletions install/data_test_api.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
INSERT INTO model.entity (
cidoc_class_code, openatlas_class_name, name, description, begin_from, begin_to, begin_comment,
end_from, end_to, end_comment, created, modified
) VALUES (
'E18', 'place', 'Shire','The Shire was the homeland of the hobbits.',
'2018-01-31', '2018-03-01', 'Begin of the shire', '2019-01-31',
'2019-03-01','Descent of Shire', '2022-09-21 16:38:01.923431',
'2022-09-21 16:38:05.923431'
);
cidoc_class_code, openatlas_class_name, name, description, begin_from, begin_to, begin_comment, end_from, end_to, end_comment, created, modified)
VALUES
('E18', 'place', 'Shire','The Shire was the homeland of the hobbits.','2018-01-31', '2018-03-01', 'Begin of the shire', '2019-01-31', '2019-03-01','Descent of Shire', '2022-09-21 16:38:01.923431','2022-09-21 16:38:05.923431'),
('E21', 'person', 'Sam', 'That is Sam','200-01-31', '200-03-01', 'Begin of the shire', '700-01-31', '800-03-01','Descent of Shire', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

INSERT INTO model.entity (cidoc_class_code, openatlas_class_name, name, description, modified)
VALUES
Expand All @@ -25,7 +21,6 @@ VALUES
('E31', 'file', 'File not public', NULL, CURRENT_TIMESTAMP),
('E33', 'source', 'Silmarillion', NULL, CURRENT_TIMESTAMP),
('E21', 'person', 'Frodo', 'That is Frodo', CURRENT_TIMESTAMP),
('E21', 'person', 'Sam', 'That is Sam', CURRENT_TIMESTAMP),
('E31', 'external_reference', 'https://lotr.fandom.com/', NULL, CURRENT_TIMESTAMP),
('E41', 'appellation', 'Sûza', NULL, CURRENT_TIMESTAMP),
('E41', 'appellation', 'The ring bearer', NULL, CURRENT_TIMESTAMP),
Expand Down
7 changes: 2 additions & 5 deletions install/upgrade/8.10.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ BEGIN;

-- Raise database version
UPDATE web.settings SET value = '8.10.0' WHERE name = 'database_version';
-- Upgrade 8.9.x to 8.10.0
-- Be sure to backup the database and read the upgrade notes before executing.


CREATE TABLE IF NOT EXISTS web.user_tokens
(
-- #1233: API: External Authentication
CREATE TABLE IF NOT EXISTS web.user_tokens (
id integer NOT NULL,
user_id integer NOT NULL,
creator_id integer NOT NULL,
Expand Down
3 changes: 2 additions & 1 deletion install/upgrade/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ then run the database upgrade script, then restart Apache:
sudo service apache2 restart

### 8.9.0 to 8.10.0
No database update is required but an additional Python package is needed:
8.10.0.sql is needed but will be taken care of by the database upgrade script.
Additional Python packages are needed:

sudo apt install python3-jwt python3-python-flask-jwt-extended

Expand Down
4 changes: 2 additions & 2 deletions openatlas/api/endpoints/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def export_csv_entities(self) -> Response:
frames = []
for e in self.entities_with_links.values():
data = build_dataframe(e['entity'])
for k, v in (get_csv_links(e) | get_csv_types(e)).items():
data[k] = ' | '.join(list(map(str, v)))
for key, value in (get_csv_links(e) | get_csv_types(e)).items():
data[key] = ' | '.join(list(map(str, value)))
frames.append(data)
return Response(
pd.DataFrame(data=frames).to_csv(),
Expand Down
25 changes: 19 additions & 6 deletions openatlas/api/endpoints/entities.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from typing import Any

from flask import Response, g
from flask_restful import Resource
from flask_restful import Resource, marshal

from openatlas.api.endpoints.endpoint import Endpoint
from openatlas.api.formats.presentation_view import get_presentation_view
from openatlas.api.resources.api_entity import ApiEntity
from openatlas.api.resources.error import (
InvalidLimitError, NotATypeError, QueryEmptyError)
from openatlas.api.resources.parser import entity_, properties, query
from openatlas.api.resources.templates import presentation_template
from openatlas.api.resources.util import (
get_entities_from_type_with_subs, get_entities_linked_to_special_type,
get_entities_linked_to_special_type_recursive, get_linked_entities_api)
Expand All @@ -20,6 +22,7 @@ def get(class_: str) -> tuple[Resource, int] | Response | dict[str, Any]:
ApiEntity.get_by_cidoc_classes([class_]),
entity_.parse_args()).resolve_entities()


class GetBySystemClass(Resource):
@staticmethod
def get(class_: str) -> tuple[Resource, int] | Response | dict[str, Any]:
Expand All @@ -44,6 +47,16 @@ def get(id_: int) -> tuple[Resource, int] | Response | dict[str, Any]:
entity_.parse_args()).resolve_entities()


class GetEntityPresentationView(Resource):
@staticmethod
def get(id_: int) -> tuple[Resource, int] | Response | dict[str, Any]:
return marshal(
get_presentation_view(
ApiEntity.get_by_id(id_, types=True, aliases=True),
entity_.parse_args()),
presentation_template())


class GetLinkedEntitiesByPropertyRecursive(Resource):
@staticmethod
def get(id_: int) -> Response | dict[str, Any]:
Expand Down Expand Up @@ -105,11 +118,11 @@ class GetQuery(Resource):
def get() -> tuple[Resource, int] | Response | dict[str, Any]:
parser = query.parse_args()
if not any([
parser['entities'],
parser['cidoc_classes'],
parser['view_classes'],
parser['system_classes'],
parser['linked_entities']]):
parser['entities'],
parser['cidoc_classes'],
parser['view_classes'],
parser['system_classes'],
parser['linked_entities']]):
raise QueryEmptyError
entities = []
if parser['entities']:
Expand Down
11 changes: 5 additions & 6 deletions openatlas/api/endpoints/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from openatlas.api.resources.util import (
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)
get_value_for_types, replace_empty_list_values_in_dict_with_none)
from openatlas.models.entity import Entity, Link
from openatlas.models.gis import Gis

Expand Down Expand Up @@ -71,6 +71,8 @@ def __init__(self, parser: dict[str, Any]):
self.is_valid_url()
if self.url and not self.url.endswith('/'):
self.url += '/'
if self.centroid:
self.centroid = parser['centroid'] == 'true'

def set_search_param(self) -> None:
try:
Expand Down Expand Up @@ -192,6 +194,7 @@ def get_geom(self, entity: Entity, ) -> list[Any]:
return geoms
return []


def get_linked_places_entity(
self,
entity_dict: dict[str, Any]) -> dict[str, Any]:
Expand Down Expand Up @@ -319,10 +322,6 @@ def get_lp_types(
'identifier': url_for(
'api.entity', id_=g.types[root].id, _external=True)}
for root in type_.root]}
for link in links:
if link.range.id == type_.id and link.description:
type_dict['value'] = link.description
if link.range.id == type_.id and type_.description:
type_dict['unit'] = type_.description
type_dict.update(get_value_for_types(type_, links))
types.append(type_dict)
return types
26 changes: 8 additions & 18 deletions openatlas/api/formats/linked_places.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from openatlas.api.resources.util import (
date_to_str, get_crm_relation, get_crm_relation_label_x,
get_crm_relation_x, get_license_name, to_camel_case)
from openatlas.display.util import (
check_iiif_activation, check_iiif_file_exist, get_file_path)
get_crm_relation_x, get_iiif_manifest_and_path, get_license_name,
to_camel_case)
from openatlas.display.util import get_file_path
from openatlas.models.entity import Entity, Link

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -73,23 +73,12 @@ def get_lp_file(links_inverse: list[Link]) -> list[dict[str, str]]:
for link in links_inverse:
if link.domain.class_.name != 'file':
continue
iiif_manifest = ''
iiif_base_path= ''
img_id = link.domain.id
if check_iiif_activation() and check_iiif_file_exist(img_id):
iiif_manifest = url_for(
'api.iiif_manifest',
version=g.settings['iiif_version'],
id_=img_id,
_external=True)
if g.files.get(img_id):
iiif_base_path =\
f"{g.settings['iiif_url']}{img_id}{g.files[img_id].suffix}"
path = get_file_path(img_id)
mime_type = None
if path:
mime_type, _ = mimetypes.guess_type(path)
files.append({
data = {
'@id': url_for(
'api.entity',
id_=img_id,
Expand All @@ -100,12 +89,13 @@ def get_lp_file(links_inverse: list[Link]) -> list[dict[str, str]]:
'licenseHolder': link.domain.license_holder,
'publicShareable': link.domain.public,
'mimetype': mime_type,
'IIIFManifest': iiif_manifest,
'IIIFBasePath': iiif_base_path,
'url': url_for(
'api.display',
filename=path.stem,
_external=True) if path else "N/A"})
_external=True) if path else "N/A"}
data.update(get_iiif_manifest_and_path(img_id))
files.append(data)

return files


Expand Down
Loading

0 comments on commit 540d3cb

Please sign in to comment.